bluetooth: Add support for getting current active codec
authorSanchayan Maity <sanchayan@asymptotic.io>
Fri, 1 Jan 2021 06:18:11 +0000 (11:48 +0530)
committerSanchayan Maity <sanchayan@asymptotic.io>
Tue, 19 Jan 2021 08:13:42 +0000 (13:43 +0530)
For example, using the following on the command line will return the
current codec for a bluetooth device

pacmd send-message /card/bluez_card.4C_BC_98_80_01_9B/bluez get-codec

where 4C_BC_98_80_01_9B is the bluetooth device.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/440>

src/modules/bluetooth/module-bluez5-device.c

index 95287f1..4ad0b95 100644 (file)
@@ -2419,6 +2419,18 @@ static int bluez5_device_message_handler(const char *object_path, const char *me
     } else if (pa_streq(message, "list-codecs")) {
         *response = list_codecs(u);
         return PA_OK;
+    } else if (pa_streq(message, "get-codec")) {
+        pa_message_params *param;
+        param = pa_message_params_new();
+
+        if (u->a2dp_codec)
+            pa_message_params_write_string(param, u->a2dp_codec->name);
+        else
+            pa_message_params_write_string(param, "none");
+
+        *response = pa_message_params_to_string_free(param);
+
+        return PA_OK;
     }