From e9d869b46f0bbd61632ee5a8f6c4797f41ce9243 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 23 Sep 2021 14:25:32 +1000 Subject: [PATCH] spa: implement a log topic for alsa --- spa/plugins/alsa/alsa-acp-device.c | 5 +++- spa/plugins/alsa/alsa-pcm-device.c | 4 ++- spa/plugins/alsa/alsa-pcm-sink.c | 1 + spa/plugins/alsa/alsa-pcm-source.c | 4 +++ spa/plugins/alsa/alsa-pcm.h | 3 ++- spa/plugins/alsa/alsa-seq-bridge.c | 2 ++ spa/plugins/alsa/alsa-seq.c | 2 ++ spa/plugins/alsa/alsa-seq.h | 3 ++- spa/plugins/alsa/alsa-udev.c | 4 ++- spa/plugins/alsa/alsa.c | 4 +++ spa/plugins/alsa/alsa.h | 39 ++++++++++++++++++++++++++++++ spa/plugins/alsa/meson.build | 1 + 12 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 spa/plugins/alsa/alsa.h diff --git a/spa/plugins/alsa/alsa-acp-device.c b/spa/plugins/alsa/alsa-acp-device.c index a295573a6..4ba510e9d 100644 --- a/spa/plugins/alsa/alsa-acp-device.c +++ b/spa/plugins/alsa/alsa-acp-device.c @@ -31,7 +31,6 @@ #include -#include #include #include #include @@ -48,6 +47,8 @@ #include #include +#include "alsa.h" + #include "acp/acp.h" extern struct spa_i18n *acp_i18n; @@ -1043,6 +1044,8 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); + alsa_log_topic_init(this->log); + this->loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop); acp_i18n = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_I18N); if (this->loop == NULL) { diff --git a/spa/plugins/alsa/alsa-pcm-device.c b/spa/plugins/alsa/alsa-pcm-device.c index e1d6b2a3b..230fc1923 100644 --- a/spa/plugins/alsa/alsa-pcm-device.c +++ b/spa/plugins/alsa/alsa-pcm-device.c @@ -31,7 +31,6 @@ #include -#include #include #include #include @@ -46,6 +45,8 @@ #include #include +#include "alsa.h" + #define NAME "alsa-device" #define MAX_DEVICES 64 @@ -532,6 +533,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); + alsa_log_topic_init(this->log); this->device.iface = SPA_INTERFACE_INIT( SPA_TYPE_INTERFACE_Device, diff --git a/spa/plugins/alsa/alsa-pcm-sink.c b/spa/plugins/alsa/alsa-pcm-sink.c index 46e773de0..1b0a7235d 100644 --- a/spa/plugins/alsa/alsa-pcm-sink.c +++ b/spa/plugins/alsa/alsa-pcm-sink.c @@ -926,6 +926,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct state *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); + alsa_log_topic_init(this->log); this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem); this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop); diff --git a/spa/plugins/alsa/alsa-pcm-source.c b/spa/plugins/alsa/alsa-pcm-source.c index 794bb1191..0f37cba64 100644 --- a/spa/plugins/alsa/alsa-pcm-source.c +++ b/spa/plugins/alsa/alsa-pcm-source.c @@ -37,6 +37,8 @@ #include #include +#include "alsa.h" + #define NAME "alsa-pcm-source" #include "alsa-pcm.h" @@ -873,6 +875,8 @@ impl_init(const struct spa_handle_factory *factory, this = (struct state *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); + alsa_log_topic_init(this->log); + this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem); this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop); diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index c6e44886b..d2a2210d6 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -37,7 +37,6 @@ extern "C" { #include #include -#include #include #include @@ -49,6 +48,8 @@ extern "C" { #include #include +#include "alsa.h" + #include "dll.h" #define MIN_LATENCY 16 diff --git a/spa/plugins/alsa/alsa-seq-bridge.c b/spa/plugins/alsa/alsa-seq-bridge.c index 57db2eda5..c01b374b4 100644 --- a/spa/plugins/alsa/alsa-seq-bridge.c +++ b/spa/plugins/alsa/alsa-seq-bridge.c @@ -884,6 +884,8 @@ impl_init(const struct spa_handle_factory *factory, this = (struct seq_state *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); + alsa_log_topic_init(this->log); + spa_log_info(this->log, "this is an alsa message"); this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem); this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop); this->main_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop); diff --git a/spa/plugins/alsa/alsa-seq.c b/spa/plugins/alsa/alsa-seq.c index 6be92c9cb..1a31d16f8 100644 --- a/spa/plugins/alsa/alsa-seq.c +++ b/spa/plugins/alsa/alsa-seq.c @@ -37,6 +37,8 @@ #include #include +#include "alsa.h" + #define NAME "alsa-seq" #include "dll.h" diff --git a/spa/plugins/alsa/alsa-seq.h b/spa/plugins/alsa/alsa-seq.h index c66ed7187..a5f6f1f78 100644 --- a/spa/plugins/alsa/alsa-seq.h +++ b/spa/plugins/alsa/alsa-seq.h @@ -36,7 +36,6 @@ extern "C" { #include #include -#include #include #include @@ -46,6 +45,8 @@ extern "C" { #include #include +#include "alsa.h" + #include "dll.h" struct props { diff --git a/spa/plugins/alsa/alsa-udev.c b/spa/plugins/alsa/alsa-udev.c index 685daef59..5aee93aee 100644 --- a/spa/plugins/alsa/alsa-udev.c +++ b/spa/plugins/alsa/alsa-udev.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -44,6 +43,8 @@ #include #include +#include "alsa.h" + #define NAME "alsa-udev" #define MAX_DEVICES 64 @@ -759,6 +760,7 @@ impl_init(const struct spa_handle_factory *factory, this->notify.fd = -1; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); + alsa_log_topic_init(this->log); this->main_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop); if (this->main_loop == NULL) { diff --git a/spa/plugins/alsa/alsa.c b/spa/plugins/alsa/alsa.c index f00dc2438..61e67f8a0 100644 --- a/spa/plugins/alsa/alsa.c +++ b/spa/plugins/alsa/alsa.c @@ -25,6 +25,7 @@ #include #include +#include extern const struct spa_handle_factory spa_alsa_source_factory; extern const struct spa_handle_factory spa_alsa_sink_factory; @@ -33,6 +34,9 @@ extern const struct spa_handle_factory spa_alsa_device_factory; extern const struct spa_handle_factory spa_alsa_seq_bridge_factory; extern const struct spa_handle_factory spa_alsa_acp_device_factory; +struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.alsa"); +struct spa_log_topic *alsa_log_topic = &log_topic; + SPA_EXPORT int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index) { diff --git a/spa/plugins/alsa/alsa.h b/spa/plugins/alsa/alsa.h new file mode 100644 index 000000000..ee189294a --- /dev/null +++ b/spa/plugins/alsa/alsa.h @@ -0,0 +1,39 @@ +/* Spa ALSA Source + * + * Copyright © 2021 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef SPA_ALSA_H +#define SPA_ALSA_H + +#include + +#undef SPA_LOG_TOPIC_DEFAULT +#define SPA_LOG_TOPIC_DEFAULT alsa_log_topic +extern struct spa_log_topic *alsa_log_topic; + +static inline void alsa_log_topic_init(struct spa_log *log) +{ + spa_log_topic_init(log, alsa_log_topic); +} + +#endif /* SPA_ALSA_H */ diff --git a/spa/plugins/alsa/meson.build b/spa/plugins/alsa/meson.build index c0977f15d..402d93486 100644 --- a/spa/plugins/alsa/meson.build +++ b/spa/plugins/alsa/meson.build @@ -2,6 +2,7 @@ subdir('acp') subdir('mixer') spa_alsa_sources = ['alsa.c', + 'alsa.h', 'alsa-udev.c', 'alsa-acp-device.c', 'alsa-pcm-device.c',