From 8504e58120cc2b80feae81261f1dd47a4f574771 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 30 Jun 2024 17:09:43 +0300 Subject: [PATCH] bluez5: reduce quirks logspam There's no need to log quirks every time they are used, it's enough to log them once when a device connects. --- spa/plugins/bluez5/bluez5-dbus.c | 5 ++-- spa/plugins/bluez5/defs.h | 3 +++ spa/plugins/bluez5/quirks.c | 42 ++++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index f0e097388..bc1101a87 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -2075,9 +2075,10 @@ static void device_set_connected(struct spa_bt_device *device, int connected) if (device->connected && !connected) device->connected_profiles = 0; - if (connected) + if (connected) { + spa_bt_quirks_log_features(monitor->quirks, device->adapter, device); spa_bt_device_check_profiles(device, false); - else { + } else { /* Stop codec switch on disconnect */ struct spa_bt_media_codec_switch *sw; spa_list_consume(sw, &device->codec_switch_list, device_link) diff --git a/spa/plugins/bluez5/defs.h b/spa/plugins/bluez5/defs.h index 7bdd49ad7..7fe7bd06c 100644 --- a/spa/plugins/bluez5/defs.h +++ b/spa/plugins/bluez5/defs.h @@ -778,6 +778,9 @@ int spa_bt_quirks_get_features(const struct spa_bt_quirks *quirks, const struct spa_bt_adapter *adapter, const struct spa_bt_device *device, uint32_t *features); +void spa_bt_quirks_log_features(const struct spa_bt_quirks *this, + const struct spa_bt_adapter *adapter, + const struct spa_bt_device *device); void spa_bt_quirks_destroy(struct spa_bt_quirks *quirks); int spa_bt_adapter_has_msbc(struct spa_bt_adapter *adapter); diff --git a/spa/plugins/bluez5/quirks.c b/spa/plugins/bluez5/quirks.c index fc89e1b8b..c4b293e68 100644 --- a/spa/plugins/bluez5/quirks.c +++ b/spa/plugins/bluez5/quirks.c @@ -278,10 +278,11 @@ static void strtolower(char *src, char *dst, int maxsize) *dst = '\0'; } -int spa_bt_quirks_get_features(const struct spa_bt_quirks *this, +static int get_features(const struct spa_bt_quirks *this, const struct spa_bt_adapter *adapter, const struct spa_bt_device *device, - uint32_t *features) + uint32_t *features, + bool debug) { struct spa_dict props; struct spa_dict_item items[5]; @@ -294,15 +295,18 @@ int spa_bt_quirks_get_features(const struct spa_bt_quirks *this, uint32_t no_features = 0; int nitems = 0; struct utsname name; + if ((res = uname(&name)) < 0) return res; items[nitems++] = SPA_DICT_ITEM_INIT("sysname", name.sysname); items[nitems++] = SPA_DICT_ITEM_INIT("release", name.release); items[nitems++] = SPA_DICT_ITEM_INIT("version", name.version); props = SPA_DICT_INIT(items, nitems); - log_props(this->log, &props); + if (debug) + log_props(this->log, &props); do_match(this->kernel_rules, &props, &no_features); - spa_log_debug(this->log, "kernel quirks:%08x", no_features); + if (debug) + spa_log_debug(this->log, "kernel quirks:%08x", no_features); *features &= ~no_features; } @@ -325,9 +329,11 @@ int spa_bt_quirks_get_features(const struct spa_bt_quirks *this, items[nitems++] = SPA_DICT_ITEM_INIT("address", address); } props = SPA_DICT_INIT(items, nitems); - log_props(this->log, &props); + if (debug) + log_props(this->log, &props); do_match(this->adapter_rules, &props, &no_features); - spa_log_debug(this->log, "adapter quirks:%08x", no_features); + if (debug) + spa_log_debug(this->log, "adapter quirks:%08x", no_features); *features &= ~no_features; } @@ -352,9 +358,11 @@ int spa_bt_quirks_get_features(const struct spa_bt_quirks *this, items[nitems++] = SPA_DICT_ITEM_INIT("address", address); } props = SPA_DICT_INIT(items, nitems); - log_props(this->log, &props); + if (debug) + log_props(this->log, &props); do_match(this->device_rules, &props, &no_features); - spa_log_debug(this->log, "device quirks:%08x", no_features); + if (debug) + spa_log_debug(this->log, "device quirks:%08x", no_features); *features &= ~no_features; } @@ -379,3 +387,21 @@ int spa_bt_quirks_get_features(const struct spa_bt_quirks *this, return 0; } + +int spa_bt_quirks_get_features(const struct spa_bt_quirks *this, + const struct spa_bt_adapter *adapter, + const struct spa_bt_device *device, + uint32_t *features) +{ + return get_features(this, adapter, device, features, false); +} + +void spa_bt_quirks_log_features(const struct spa_bt_quirks *this, + const struct spa_bt_adapter *adapter, + const struct spa_bt_device *device) +{ + uint32_t features = 0; + + get_features(this, adapter, device, &features, true); + spa_log_debug(this->log, "features:%08x", features); +}