diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-07-31 13:33:28 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-07-31 13:33:28 +0200 |
commit | 47ce3746366060dd5e410de9558ee1d1582ea52c (patch) | |
tree | 2bc3fbf55dc2695daf8b3f7d0ec0bee815290d7b | |
parent | c388df1cf3fd226973bed3652f2af0499983a26a (diff) |
pulse: refactor param enumeration
-rw-r--r-- | pipewire-pulseaudio/src/context.c | 45 | ||||
-rw-r--r-- | pipewire-pulseaudio/src/internal.h | 1 |
2 files changed, 27 insertions, 19 deletions
diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c index 12d7d279..c6235630 100644 --- a/pipewire-pulseaudio/src/context.c +++ b/pipewire-pulseaudio/src/context.c @@ -276,6 +276,29 @@ static void emit_event(pa_context *c, struct global *g, pa_subscription_event_ty } } +static struct param *add_param(struct spa_list *params, uint32_t id, const struct spa_pod *param) +{ + struct param *p; + + if (param == NULL || !spa_pod_is_object(param)) { + errno = EINVAL; + return NULL; + } + if (id == SPA_ID_INVALID) + id = SPA_POD_OBJECT_ID(param); + + p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); + if (p == NULL) + return NULL; + + p->id = id; + p->param = SPA_MEMBER(p, sizeof(struct param), struct spa_pod); + memcpy(p->param, param, SPA_POD_SIZE(param)); + spa_list_append(params, &p->link); + + return p; +} + static void remove_params(struct spa_list *params, uint32_t id) { struct param *p, *t; @@ -445,7 +468,6 @@ static void device_event_param(void *object, int seq, { uint32_t index; const char *name; - struct param *p; if (spa_pod_parse_object(param, SPA_TYPE_OBJECT_ParamProfile, NULL, @@ -454,15 +476,9 @@ static void device_event_param(void *object, int seq, pw_log_warn("device %d: can't parse profile", g->id); return; } - p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); - if (p) { - p->id = id; - p->seq = seq; - p->param = SPA_MEMBER(p, sizeof(struct param), struct spa_pod); - memcpy(p->param, param, SPA_POD_SIZE(param)); - spa_list_append(&g->card_info.profiles, &p->link); + if (add_param(&g->card_info.profiles, id, param)) g->card_info.n_profiles++; - } + pw_log_debug("device %d: enum profile %d: \"%s\" n_profiles:%d", g->id, index, name, g->card_info.n_profiles); break; @@ -484,7 +500,6 @@ static void device_event_param(void *object, int seq, { uint32_t index; const char *name; - struct param *p; if (spa_pod_parse_object(param, SPA_TYPE_OBJECT_ParamRoute, NULL, @@ -493,15 +508,9 @@ static void device_event_param(void *object, int seq, pw_log_warn("device %d: can't parse route", g->id); return; } - p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); - if (p) { - p->id = id; - p->seq = seq; - p->param = SPA_MEMBER(p, sizeof(struct param), struct spa_pod); - memcpy(p->param, param, SPA_POD_SIZE(param)); - spa_list_append(&g->card_info.ports, &p->link); + if (add_param(&g->card_info.ports, id, param)) g->card_info.n_ports++; - } + pw_log_debug("device %d: enum route %d: \"%s\"", g->id, index, name); break; } diff --git a/pipewire-pulseaudio/src/internal.h b/pipewire-pulseaudio/src/internal.h index 71d3e7f6..4cbb42ff 100644 --- a/pipewire-pulseaudio/src/internal.h +++ b/pipewire-pulseaudio/src/internal.h @@ -224,7 +224,6 @@ struct pa_mainloop { struct param { struct spa_list link; uint32_t id; - int seq; void *param; }; |