diff mbox series

[BlueZ,4/4] client: implement SelectQoS

Message ID c00fc1a3659ec7e7f77a6c2029e25dac3e6ee754.1698503903.git.pav@iki.fi
State New
Headers show
Series [BlueZ,1/4] doc: extend MediaEndpoint1 API with SelectQoS | expand

Commit Message

Pauli Virtanen Oct. 28, 2023, 2:39 p.m. UTC
Implement SelectQoS() so that the server-provided values get printed.
We don't take them into account yet otherwise, though.
---
 client/player.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
diff mbox series

Patch

diff --git a/client/player.c b/client/player.c
index 715598aa9..4ad6b99d9 100644
--- a/client/player.c
+++ b/client/player.c
@@ -91,6 +91,7 @@  struct endpoint {
 	struct queue *transports;
 	DBusMessage *msg;
 	struct preset *preset;
+	struct codec_preset *codec_preset;
 	bool broadcast;
 	struct iovec *bcode;
 };
@@ -2078,6 +2079,8 @@  static void select_properties_response(const char *input, void *user_data)
 	p = preset_find_name(ep->preset, input);
 	if (p) {
 		reply = endpoint_select_properties_reply(ep, ep->msg, p);
+		if (reply)
+			ep->codec_preset = p;
 		goto done;
 	}
 
@@ -2130,6 +2133,49 @@  static DBusMessage *endpoint_select_properties(DBusConnection *conn,
 	return reply;
 }
 
+static DBusMessage *endpoint_select_qos(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct endpoint *ep = user_data;
+	struct codec_preset *preset = ep->codec_preset;
+	DBusMessageIter args;
+	DBusMessageIter iter, dict;
+	DBusMessage *reply;
+	struct endpoint_config cfg;
+
+	dbus_message_iter_init(msg, &args);
+
+	bt_shell_printf("Endpoint: SelectQoS\n");
+	print_iter("\t", "Properties", &args);
+
+	if (!preset)
+		return g_dbus_create_error(msg, "org.bluez.Error.Rejected",
+						"No previous codec preset");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &dict);
+
+	/* TODO: we ignore BAP Server supported values here. If they are not
+	 * suitable for the preset, we should prompt for a preset again, and
+	 * call SetConfiguration on the remote endpoint with the new
+	 * configuration to retry.
+	 */
+
+	memset(&cfg, 0, sizeof(cfg));
+	cfg.ep = ep;
+	cfg.qos = &preset->qos;
+	append_qos(&dict, &cfg);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
+}
+
 static bool match_str(const void *data, const void *user_data)
 {
 	return !strcmp(data, user_data);
@@ -2248,6 +2294,10 @@  static const GDBusMethodTable endpoint_methods[] = {
 					GDBUS_ARGS({ "properties", "a{sv}" } ),
 					GDBUS_ARGS({ "properties", "a{sv}" } ),
 					endpoint_select_properties) },
+	{ GDBUS_ASYNC_METHOD("SelectQoS",
+					GDBUS_ARGS({ "properties", "a{sv}" } ),
+					GDBUS_ARGS({ "properties", "a{sv}" } ),
+					endpoint_select_qos) },
 	{ GDBUS_ASYNC_METHOD("ClearConfiguration",
 					GDBUS_ARGS({ "transport", "o" } ),
 					NULL, endpoint_clear_configuration) },