public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH BlueZ 0/9] BAP stream reconfiguration
@ 2025-03-01 15:57 Pauli Virtanen
  2025-03-01 15:57 ` [RFC PATCH BlueZ 1/9] org.bluez.MediaEndpoint: removing BAP streams with ClearConfiguration Pauli Virtanen
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Pauli Virtanen @ 2025-03-01 15:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

Proposed DBus API extension is:

- org.bluez.MediaEndpoint.ClearConfiguration(transport_path):

  Destroy stream associated with transport

- org.bluez.MediaEndpoint.ClearConfiguration(remote_endpoint_path):

  Destroy all streams associated with endpoint

- org.bluez.MediaEndpoint.SelectProperties(remote_endpoint_path):

  Destroy streams of endpoint, and re-run same unicast configuration as
  on initial connect, which invokes SelectProperties() callbacks on
  sound server and it can return new configuration it wants.

For future:

- org.bluez.MediaEndpoint.SetConfiguration(...):

  I think how this already works for broadcast is good: one call creates
  one new stream. Unicast should be changed to work exactly the same
  way.

  This allows for more detailed control of the configuration than
  SelectProperties(), and sound server can use it if it wants to deal
  with the different ASE configurations by itself.

- We will need to figure out how to handle devices rejecting ASE
  configurations on Config Codec or Enable.

  Whose responsibility is it to try a different configuration, if the
  current configuration is rejected by device?

  Example: Sony Linkbuds S has 48kHz sink & 48kHz source PACs.  However,
  it does not support the duplx configuration with both 48kHz sink and
  48kHz source ASE -- it rejects that in Enable.  It does support 32 kHz
  sink + 32kHz source duplex configuration.  AFAICS it is not possible
  to know which combinations of sinks & sources are possible, except
  trying them one by one. How do we handle this?

Unicast works with this Pipewire branch (can reconfigure to
sink/source/duplex):
https://gitlab.freedesktop.org/pvir/pipewire/-/tree/bap-codec-switch-select

(With device sets, each device needs to be switched separately.  Some
more work is needed to make reconfiguration while CIG is active to work
correctly, sound server must release transports before reconfiguring.)

Broadcast has not been tested at all.

Pauli Virtanen (9):
  org.bluez.MediaEndpoint: removing BAP streams with ClearConfiguration
  org.bluez.MediaEndpoint: add client role SelectProperties
  bap: add and use chainable future abstraction
  bap: use futures for select operation
  shared/bap: bap_abort_stream_req() should cancel also current req
  shared/bap: make sure ucast client stream is destroyed after releasing
  bap: support removing streams with ClearConfiguration()
  bap: do not try QoS before links are updated & io created
  bap: implement client role SelectProperties()

 doc/org.bluez.MediaEndpoint.rst |  27 ++
 profiles/audio/bap.c            | 533 ++++++++++++++++++++++++++------
 profiles/audio/transport.c      |  17 +
 profiles/audio/transport.h      |   1 +
 src/shared/bap.c                |  39 ++-
 5 files changed, 522 insertions(+), 95 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 19+ messages in thread
* [PATCH BlueZ v3 01/10] bap: do not try QoS before links are updated & io created
@ 2025-06-08 21:32 Pauli Virtanen
  2025-06-08 22:55 ` BAP stream reconfiguration bluez.test.bot
  0 siblings, 1 reply; 19+ messages in thread
From: Pauli Virtanen @ 2025-06-08 21:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

In setup config, QoS must be done after corresponding bap_state
callback, because stream links are updated only at that point.  If the
ASE was in CONFIG state before reconfiguration, this gets done in wrong
order.

Track explicitly that bap_state() is done after bt_bap_stream_config(),
before proceeding to QoS.
---
 profiles/audio/bap.c | 82 ++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 33 deletions(-)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index ee7c8bc49..b420354cd 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -75,6 +75,7 @@ struct bap_setup {
 	bool recreate;
 	bool cig_active;
 	uint8_t sid;
+	bool config_pending;
 	struct iovec *caps;
 	struct iovec *metadata;
 	unsigned int id;
@@ -720,6 +721,46 @@ static void qos_cb(struct bt_bap_stream *stream, uint8_t code, uint8_t reason,
 	setup->msg = NULL;
 }
 
+static void setup_create_io(struct bap_data *data, struct bap_setup *setup,
+				struct bt_bap_stream *stream, int defer);
+
+static int setup_qos(struct bap_setup *setup)
+{
+	struct bap_data *data = setup->ep->data;
+	struct bt_bap_stream *stream = setup->stream;
+
+	if (!stream)
+		return -EINVAL;
+	if (bt_bap_stream_get_state(stream) != BT_BAP_STREAM_STATE_CONFIG)
+		goto error;
+	if (setup->id)
+		goto error;
+
+	setup_create_io(data, setup, stream, true);
+	if (!setup->io) {
+		error("Unable to create io");
+		goto error;
+	}
+
+	/* Wait QoS response to respond */
+	setup->id = bt_bap_stream_qos(stream, &setup->qos, qos_cb, setup);
+	if (!setup->id) {
+		error("Failed to Configure QoS");
+		goto error;
+	}
+
+	/* Bcast does not call the callback */
+	if (bt_bap_stream_get_type(setup->stream) == BT_BAP_STREAM_TYPE_BCAST)
+		setup->id = 0;
+
+	return 0;
+
+error:
+	if (bt_bap_stream_get_state(stream) != BT_BAP_STREAM_STATE_RELEASING)
+		bt_bap_stream_release(stream, NULL, NULL);
+	return -EIO;
+}
+
 static void config_cb(struct bt_bap_stream *stream,
 					uint8_t code, uint8_t reason,
 					void *user_data)
@@ -732,17 +773,8 @@ static void config_cb(struct bt_bap_stream *stream,
 	setup->id = 0;
 
 	if (!code) {
-		/* Check state is already set to config then proceed to qos */
-		if (bt_bap_stream_get_state(stream) ==
-					BT_BAP_STREAM_STATE_CONFIG) {
-			setup->id = bt_bap_stream_qos(stream, &setup->qos,
-							qos_cb, setup);
-			if (!setup->id) {
-				error("Failed to Configure QoS");
-				bt_bap_stream_release(stream, NULL, NULL);
-			}
-		}
-
+		if (!setup->config_pending)
+			setup_qos(setup);
 		return;
 	}
 
@@ -984,6 +1016,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_set_user_data(setup->stream, ep->path);
+	setup->config_pending = true;
 	setup->id = bt_bap_stream_config(setup->stream, &setup->qos,
 						setup->caps, config_cb, setup);
 	if (!setup->id) {
@@ -1003,6 +1036,7 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
 	case BT_BAP_STREAM_TYPE_BCAST:
 		/* No message sent over the air for broadcast */
 		setup->id = 0;
+		setup->config_pending = false;
 
 		if (ep->data->service)
 			service_set_connecting(ep->data->service);
@@ -1401,6 +1435,7 @@ static void setup_config(void *data, void *user_data)
 						ep->rpac, &setup->qos,
 						setup->caps);
 
+	setup->config_pending = true;
 	setup->id = bt_bap_stream_config(setup->stream, &setup->qos,
 						setup->caps, config_cb, setup);
 	if (!setup->id) {
@@ -1805,9 +1840,6 @@ static bool is_cig_busy(struct bap_data *data, uint8_t cig)
 	return queue_find(sessions, cig_busy_session, &info);
 }
 
-static void setup_create_io(struct bap_data *data, struct bap_setup *setup,
-				struct bt_bap_stream *stream, int defer);
-
 static gboolean setup_io_recreate(void *user_data)
 {
 	struct bap_setup *setup = user_data;
@@ -2187,25 +2219,9 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
 			queue_remove(data->server_streams, stream);
 		break;
 	case BT_BAP_STREAM_STATE_CONFIG:
-		if (setup && !setup->id) {
-			setup_create_io(data, setup, stream, true);
-			if (!setup->io) {
-				error("Unable to create io");
-				if (old_state != BT_BAP_STREAM_STATE_RELEASING)
-					bt_bap_stream_release(stream, NULL,
-								NULL);
-				return;
-			}
-
-			/* Wait QoS response to respond */
-			setup->id = bt_bap_stream_qos(stream,
-							&setup->qos,
-							qos_cb,	setup);
-			if (!setup->id) {
-				error("Failed to Configure QoS");
-				bt_bap_stream_release(stream,
-							NULL, NULL);
-			}
+		if (setup) {
+			setup->config_pending = false;
+			setup_qos(setup);
 		}
 		break;
 	case BT_BAP_STREAM_STATE_QOS:
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-06-08 22:55 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-01 15:57 [RFC PATCH BlueZ 0/9] BAP stream reconfiguration Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 1/9] org.bluez.MediaEndpoint: removing BAP streams with ClearConfiguration Pauli Virtanen
2025-03-01 17:12   ` BAP stream reconfiguration bluez.test.bot
2025-03-17 18:10   ` [RFC PATCH BlueZ 1/9] org.bluez.MediaEndpoint: removing BAP streams with ClearConfiguration Luiz Augusto von Dentz
2025-03-17 19:23     ` Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 2/9] org.bluez.MediaEndpoint: add client role SelectProperties Pauli Virtanen
2025-03-17 18:20   ` Luiz Augusto von Dentz
2025-03-01 15:57 ` [RFC PATCH BlueZ 3/9] bap: add and use chainable future abstraction Pauli Virtanen
2025-03-17 18:42   ` Luiz Augusto von Dentz
2025-03-01 15:57 ` [RFC PATCH BlueZ 4/9] bap: use futures for select operation Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 5/9] shared/bap: bap_abort_stream_req() should cancel also current req Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 6/9] shared/bap: make sure ucast client stream is destroyed after releasing Pauli Virtanen
2025-03-01 16:26   ` Pauli Virtanen
2025-03-17 18:55     ` Luiz Augusto von Dentz
2025-03-17 19:14       ` Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 7/9] bap: support removing streams with ClearConfiguration() Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 8/9] bap: do not try QoS before links are updated & io created Pauli Virtanen
2025-03-01 15:57 ` [RFC PATCH BlueZ 9/9] bap: implement client role SelectProperties() Pauli Virtanen
  -- strict thread matches above, loose matches on Subject: below --
2025-06-08 21:32 [PATCH BlueZ v3 01/10] bap: do not try QoS before links are updated & io created Pauli Virtanen
2025-06-08 22:55 ` BAP stream reconfiguration bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox