From 4e44da6c4bbd83f3cab9b2be7bbe3c0013e12001 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 8 May 2020 14:16:25 +0200 Subject: [PATCH] pulse: hide the pa_proplist implementation Hide the proplist implementation. Add some more methods to update the proplist Make sure our integration functions only use exported symbols so that they even work against the original pulse implementations in case they are loaded first. Fixes #236 --- pipewire-pulseaudio/src/context.c | 2 +- pipewire-pulseaudio/src/internal.h | 4 +-- pipewire-pulseaudio/src/proplist.c | 55 ++++++++++++++++++++++++------ pipewire-pulseaudio/src/stream.c | 2 +- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c index 9dd787cfa..aef3555e2 100644 --- a/pipewire-pulseaudio/src/context.c +++ b/pipewire-pulseaudio/src/context.c @@ -894,7 +894,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * pw_properties_set(props, PA_PROP_APPLICATION_NAME, name); pw_properties_set(props, PW_KEY_CLIENT_API, "pulseaudio"); if (p) - pw_properties_update(props, &p->props->dict); + pw_properties_update_proplist(props, p); loop = mainloop->userdata; context = pw_context_new(loop, NULL, sizeof(struct pa_context)); diff --git a/pipewire-pulseaudio/src/internal.h b/pipewire-pulseaudio/src/internal.h index b52e2168f..280088557 100644 --- a/pipewire-pulseaudio/src/internal.h +++ b/pipewire-pulseaudio/src/internal.h @@ -168,13 +168,11 @@ do { \ #define PA_FAIL_RETURN_NULL(context, error) \ PA_FAIL_RETURN_ANY(context, error, NULL) -struct pa_proplist { - struct pw_properties *props; -}; pa_proplist* pa_proplist_new_props(struct pw_properties *props); pa_proplist* pa_proplist_new_dict(struct spa_dict *dict); int pa_proplist_update_dict(pa_proplist *p, struct spa_dict *dict); +int pw_properties_update_proplist(struct pw_properties *props, const pa_proplist *p); struct pa_io_event { struct spa_source *source; diff --git a/pipewire-pulseaudio/src/proplist.c b/pipewire-pulseaudio/src/proplist.c index 247920d19..7ac87c43f 100644 --- a/pipewire-pulseaudio/src/proplist.c +++ b/pipewire-pulseaudio/src/proplist.c @@ -29,18 +29,27 @@ #include "internal.h" #include "strbuf.h" +struct pa_proplist { + struct pw_properties *props; +}; + +int pa_proplist_update_dict(pa_proplist *p, struct spa_dict *dict) +{ + const struct spa_dict_item *item; + spa_dict_for_each(item, dict) + pa_proplist_sets(p, item->key, item->value); + return 0; +} + pa_proplist* pa_proplist_new_dict(struct spa_dict *dict) { pa_proplist *p; - p = calloc(1, sizeof(struct pa_proplist)); + p = pa_proplist_new(); if (p == NULL) return NULL; - if (dict) - p->props = pw_properties_new_dict(dict); - else - p->props = pw_properties_new(NULL, NULL); + pa_proplist_update_dict(p, dict); return p; } @@ -52,14 +61,16 @@ pa_proplist* pa_proplist_new_props(struct pw_properties *props) SPA_EXPORT pa_proplist* pa_proplist_new(void) { - return pa_proplist_new_dict(NULL); -} + pa_proplist *p; -int pa_proplist_update_dict(pa_proplist *p, struct spa_dict *dict) -{ - return pw_properties_update(p->props, dict); -} + p = calloc(1, sizeof(struct pa_proplist)); + if (p == NULL) + return NULL; + p->props = pw_properties_new(NULL, NULL); + + return p; +} SPA_EXPORT void pa_proplist_free(pa_proplist* p) @@ -370,3 +381,25 @@ int pa_proplist_equal(PA_CONST pa_proplist *a, PA_CONST pa_proplist *b) } return 1; } + + +int pw_properties_update_proplist(struct pw_properties *props, + const pa_proplist *p) +{ + void *state = NULL; + const char *key, *val; + int changed = 0; + + while (true) { + key = pa_proplist_iterate(p, &state); + if (key == NULL) + break; + + val = pa_proplist_gets(p, key); + if (val == NULL) + continue; + + changed += pw_properties_set(props, key, val); + } + return changed; +} diff --git a/pipewire-pulseaudio/src/stream.c b/pipewire-pulseaudio/src/stream.c index 8c3799f13..2fe450c53 100644 --- a/pipewire-pulseaudio/src/stream.c +++ b/pipewire-pulseaudio/src/stream.c @@ -622,7 +622,7 @@ static pa_stream* stream_new(pa_context *c, const char *name, props = pw_properties_new(PW_KEY_CLIENT_API, "pulseaudio", NULL); - pw_properties_update(props, &s->proplist->props->dict); + pw_properties_update_proplist(props, s->proplist); s->refcount = 1; s->context = c;