pulse: refactor param enumeration

This commit is contained in:
Wim Taymans 2020-07-31 13:33:28 +02:00
parent c388df1cf3
commit 47ce374636
2 changed files with 27 additions and 19 deletions

View file

@ -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) static void remove_params(struct spa_list *params, uint32_t id)
{ {
struct param *p, *t; struct param *p, *t;
@ -445,7 +468,6 @@ static void device_event_param(void *object, int seq,
{ {
uint32_t index; uint32_t index;
const char *name; const char *name;
struct param *p;
if (spa_pod_parse_object(param, if (spa_pod_parse_object(param,
SPA_TYPE_OBJECT_ParamProfile, NULL, 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); pw_log_warn("device %d: can't parse profile", g->id);
return; return;
} }
p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); if (add_param(&g->card_info.profiles, id, 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);
g->card_info.n_profiles++; g->card_info.n_profiles++;
}
pw_log_debug("device %d: enum profile %d: \"%s\" n_profiles:%d", g->id, pw_log_debug("device %d: enum profile %d: \"%s\" n_profiles:%d", g->id,
index, name, g->card_info.n_profiles); index, name, g->card_info.n_profiles);
break; break;
@ -484,7 +500,6 @@ static void device_event_param(void *object, int seq,
{ {
uint32_t index; uint32_t index;
const char *name; const char *name;
struct param *p;
if (spa_pod_parse_object(param, if (spa_pod_parse_object(param,
SPA_TYPE_OBJECT_ParamRoute, NULL, 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); pw_log_warn("device %d: can't parse route", g->id);
return; return;
} }
p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); if (add_param(&g->card_info.ports, id, 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);
g->card_info.n_ports++; g->card_info.n_ports++;
}
pw_log_debug("device %d: enum route %d: \"%s\"", g->id, index, name); pw_log_debug("device %d: enum route %d: \"%s\"", g->id, index, name);
break; break;
} }

View file

@ -224,7 +224,6 @@ struct pa_mainloop {
struct param { struct param {
struct spa_list link; struct spa_list link;
uint32_t id; uint32_t id;
int seq;
void *param; void *param;
}; };