diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-05-27 09:50:13 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-07-03 17:33:07 +0200 |
commit | 914967a19db120951120224c4330993acbdbfd91 (patch) | |
tree | 92b0ac65e6e6950d6e674bf0271324dd6dbc201b | |
parent | ed814fc0d6b76592e05aa7601aacaa682c90c14a (diff) |
add log
-rw-r--r-- | spa/plugins/pulse/acp.c | 34 | ||||
-rw-r--r-- | spa/plugins/pulse/acp.h | 21 | ||||
-rw-r--r-- | spa/plugins/pulse/alsa-util.c | 1 | ||||
-rw-r--r-- | spa/plugins/pulse/compat.h | 24 | ||||
-rw-r--r-- | spa/plugins/pulse/test-probe.c | 41 |
5 files changed, 100 insertions, 21 deletions
diff --git a/spa/plugins/pulse/acp.c b/spa/plugins/pulse/acp.c index ba353e6f..5d3f7e35 100644 --- a/spa/plugins/pulse/acp.c +++ b/spa/plugins/pulse/acp.c @@ -26,6 +26,10 @@ #include "alsa-mixer.h" #include "alsa-ucm.h" +int _acp_log_level = 0; +acp_log_func _acp_log_func; +void *_acp_log_data; + static void profile_free(void *data) { } @@ -52,7 +56,8 @@ static void init_device(pa_alsa_card *impl, pa_alsa_device *dev, pa_alsa_directi dev->pcm_handle = m->input_pcm; dev->device.direction = ACP_DIRECTION_INPUT; } - pa_proplist_as_dict(m->proplist, &dev->device.props); + dev->proplist = pa_proplist_new(); + pa_proplist_update(dev->proplist, PA_UPDATE_REPLACE, m->proplist); dev->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) port_free); @@ -67,7 +72,7 @@ static void add_profiles(pa_alsa_card *impl) void *state, *state2; struct acp_card_profile *cp; pa_alsa_device_port *dp; - int count = 0; + int port_count, count = 0; PA_HASHMAP_FOREACH(ap, impl->profile_set->profiles, state) { pa_alsa_mapping *m; @@ -98,6 +103,7 @@ static void add_profiles(pa_alsa_card *impl) m->sink.device.ports = m->sink.port_array.array.data; m->sink.device.n_ports = pa_dynarray_size(&m->sink.port_array); + pa_proplist_as_dict(m->sink.proplist, &m->sink.device.props); pa_dynarray_append(&ap->out.sinks, &m->sink); } cp->sinks = ap->out.sinks.array.data; @@ -125,6 +131,7 @@ static void add_profiles(pa_alsa_card *impl) m->source.device.ports = m->source.port_array.array.data; m->source.device.n_ports = pa_dynarray_size(&m->source.port_array); + pa_proplist_as_dict(m->source.proplist, &m->source.device.props); pa_dynarray_append(&ap->out.sources, &m->source); } cp->sources = ap->out.sources.array.data; @@ -139,11 +146,13 @@ static void add_profiles(pa_alsa_card *impl) pa_hashmap_put(impl->profiles, ap->profile.name, ap); pa_dynarray_init(&impl->out.ports, NULL); + port_count = 0; PA_HASHMAP_FOREACH(dp, impl->ports, state) { - int count = 0; void *state2; dp->card = impl; + dp->port.index = port_count++; pa_dynarray_init(&dp->prof, NULL); + count = 0; PA_HASHMAP_FOREACH(cp, dp->profiles, state2) { pa_dynarray_append(&dp->prof, cp); count++; @@ -215,11 +224,12 @@ static void profile_set_available(pa_alsa_card *impl, uint32_t index, struct acp_card_profile *p = impl->card.profiles[index]; enum acp_available old = p->available; + pa_log_debug("Setting profile %s to availability status %d", + p->name, status); if (old == status) return; + p->available = status; - pa_log_debug("Setting profile %s to availability status %d", - p->name, status); if (impl && impl->events && impl->events->profile_available) impl->events->profile_available(impl->user_data, index, @@ -953,8 +963,7 @@ static const char *acp_dict_lookup(const struct acp_dict *dict, const char *key) return NULL; } -struct acp_card *acp_card_new(uint32_t index, const struct acp_dict *props, - const struct acp_card_events *events, void *user_data) +struct acp_card *acp_card_new(uint32_t index, const struct acp_dict *props) { pa_alsa_card *impl; struct acp_card *card; @@ -969,8 +978,6 @@ struct acp_card *acp_card_new(uint32_t index, const struct acp_dict *props, snprintf(device_id, sizeof(device_id), "%d", index); impl->proplist = pa_proplist_new_dict(props); - impl->events = events; - impl->user_data = user_data; card = &impl->card; card->index = index; @@ -1206,3 +1213,12 @@ int acp_device_get_mute(struct acp_device *dev, bool *mute) *mute = d->muted; return 0; } +void acp_set_log_func(acp_log_func func, void *data) +{ + _acp_log_func = func; + _acp_log_data = data; +} +void acp_set_log_level(int level) +{ + _acp_log_level = level; +} diff --git a/spa/plugins/pulse/acp.h b/spa/plugins/pulse/acp.h index 126e9649..5dc6b499 100644 --- a/spa/plugins/pulse/acp.h +++ b/spa/plugins/pulse/acp.h @@ -36,6 +36,12 @@ extern "C" { #include <stdint.h> #include <poll.h> +#ifdef __GNUC__ +#define ACP_PRINTF_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) +#else +#define ACP_PRINTF_FUNC(fmt, arg1) +#endif + struct acp_dict_item { const char *key; const char *value; @@ -75,9 +81,6 @@ struct acp_card_events { void (*destroy) (void *data); - void (*log) (void *data, int level, const char *file, const char *line, - const char *func, const char *format, va_list args); - void (*props_changed) (void *data); void (*profile_changed) (void *data, uint32_t old_index, uint32_t new_index); @@ -160,8 +163,9 @@ struct acp_card { uint32_t preferred_output_port_index; }; -struct acp_card *acp_card_new(uint32_t index, - const struct acp_dict *props, +struct acp_card *acp_card_new(uint32_t index, const struct acp_dict *props); + +void acp_card_add_listener(struct acp_card *card, const struct acp_card_events *events, void *user_data); void acp_card_destroy(struct acp_card *card); @@ -181,6 +185,13 @@ int acp_device_get_volume(struct acp_device *dev, float *volume, uint32_t n_volu int acp_device_set_mute(struct acp_device *dev, bool mute); int acp_device_get_mute(struct acp_device *dev, bool *mute); +typedef void (*acp_log_func) (void *data, + int level, const char *file, int line, const char *func, + const char *fmt, va_list arg) ACP_PRINTF_FUNC(6,0); + +void acp_set_log_func(acp_log_func, void *data); +void acp_set_log_level(int level); + #ifdef __cplusplus } #endif diff --git a/spa/plugins/pulse/alsa-util.c b/spa/plugins/pulse/alsa-util.c index 0db00abc..0d2cff59 100644 --- a/spa/plugins/pulse/alsa-util.c +++ b/spa/plugins/pulse/alsa-util.c @@ -32,6 +32,7 @@ #include <modules/udev-util.h> #endif + static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_sample_format_t *f) { static const snd_pcm_format_t format_trans[] = { diff --git a/spa/plugins/pulse/compat.h b/spa/plugins/pulse/compat.h index 6b4922d3..6c9c12e6 100644 --- a/spa/plugins/pulse/compat.h +++ b/spa/plugins/pulse/compat.h @@ -36,6 +36,7 @@ extern "C" { #include <stdint.h> #include <inttypes.h> #include <stdlib.h> +#include <stdarg.h> typedef void *(*pa_copy_func_t)(const void *p); typedef void (*pa_free_cb_t)(void *p); @@ -213,8 +214,27 @@ typedef enum pa_log_level { PA_LOG_LEVEL_MAX } pa_log_level_t; -#define pa_log_level_meta(lev,f,l,func,fmt,...) ({fprintf(stderr, fmt, ##__VA_ARGS__);fputs("\n", stderr);}) -#define pa_log_levelv_meta(lev,f,l,func,fmt,ap) ({vfprintf(stderr, fmt, ap);fputs("\n", stderr);}) +extern int _acp_log_level; +extern acp_log_func _acp_log_func; +extern void * _acp_log_data; + +#define pa_log_level_enabled(lev) (_acp_log_level >= (int)(lev)) + +#define pa_log_levelv_meta(lev,f,l,func,fmt,ap) \ +({ \ + if (pa_log_level_enabled (lev) && _acp_log_func) \ + _acp_log_func(_acp_log_data,lev,f,l,func,fmt,ap); \ +}) + +static inline PA_PRINTF_FUNC(5, 6) void pa_log_level_meta(enum pa_log_level level, + const char *file, int line, const char *func, + const char *fmt, ...) +{ + va_list args; + va_start(args,fmt); + pa_log_levelv_meta(level,file,line,func,fmt,args); + va_end(args); +} #define pa_logl(lev,fmt,...) pa_log_level_meta(lev,__FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__) #define pa_log_error(fmt,...) pa_logl(PA_LOG_ERROR, fmt, ##__VA_ARGS__) diff --git a/spa/plugins/pulse/test-probe.c b/spa/plugins/pulse/test-probe.c index ecfcf782..f66fe2fe 100644 --- a/spa/plugins/pulse/test-probe.c +++ b/spa/plugins/pulse/test-probe.c @@ -36,6 +36,7 @@ struct data { bool verbose; int card; + struct acp_card *c; }; static const char *str_available(enum acp_available status) @@ -65,13 +66,19 @@ static const char *str_direction(enum acp_direction direction) static void card_profile_available(void *data, uint32_t index, enum acp_available old, enum acp_available available) { - fprintf(stderr, "profile available %s\n", str_available(available)); + struct data *d = data; + struct acp_card *c = d->c; + struct acp_card_profile *p = c->profiles[index]; + fprintf(stderr, "profile %s available %s\n", p->name, str_available(available)); } static void card_port_available(void *data, uint32_t index, enum acp_available old, enum acp_available available) { - fprintf(stderr, "port available %s\n", str_available(available)); + struct data *d = data; + struct acp_card *c = d->c; + struct acp_port *p = c->ports[index]; + fprintf(stderr, "port %s available %s\n", p->name, str_available(available)); } struct acp_card_events card_events = { @@ -88,6 +95,14 @@ static void acp_debug_dict(struct acp_dict *dict) } } +static ACP_PRINTF_FUNC(6,0) void log_func(void *data, + int level, const char *file, int line, const char *func, + const char *fmt, va_list arg) +{ + vfprintf(stderr, fmt, arg); + fprintf(stderr, "\n"); +} + static int do_probe(struct data *data) { struct acp_card *card; @@ -97,12 +112,16 @@ static int do_probe(struct data *data) uint32_t i, j; struct pollfd *pfds; int err, count; + char **s; + + acp_set_log_func(log_func, data); + acp_set_log_level(5); items[n_items++] = ACP_DICT_ITEM_INIT("use-ucm", "true"); items[n_items++] = ACP_DICT_ITEM_INIT("verbose", data->verbose ? "true" : "false"); props = ACP_DICT_INIT(items, n_items); - card = acp_card_new(data->card, &props, &card_events, data); + data->c = card = acp_card_new(data->card, &props); for (i = 0; i < card->n_profiles; i++) { struct acp_card_profile *p = card->profiles[i]; @@ -112,11 +131,21 @@ static int do_probe(struct data *data) str_available(p->available)); for (j = 0; j < p->n_sources; j++) { struct acp_device *d = p->sources[j]; - fprintf(stderr, " source %u: name:%s\n", j, d->name); + fprintf(stderr, " source %u: name:%s devices: ", j, d->name); + for (s = d->device_strings; *s; s++) { + fprintf(stderr, "%s ", *s); + } + fprintf(stderr, "\n"); + acp_debug_dict(&d->props); } for (j = 0; j < p->n_sinks; j++) { struct acp_device *d = p->sinks[j]; - fprintf(stderr, " sink %u: name:%s\n", j, d->name); + fprintf(stderr, " sink %u: name:%s devices: ", j, d->name); + for (s = d->device_strings; *s; s++) { + fprintf(stderr, "%s ", *s); + } + fprintf(stderr, "\n"); + acp_debug_dict(&d->props); } } @@ -132,6 +161,8 @@ static int do_probe(struct data *data) fprintf(stderr, "\n"); } + acp_card_add_listener(card, &card_events, data); + count = acp_card_poll_descriptors_count(card); if (count == 0) { fprintf(stderr, "card has no events...\n"); |