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
This commit is contained in:
Wim Taymans 2020-05-08 14:16:25 +02:00
parent b53cc6feb8
commit 4e44da6c4b
4 changed files with 47 additions and 16 deletions

View file

@ -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, PA_PROP_APPLICATION_NAME, name);
pw_properties_set(props, PW_KEY_CLIENT_API, "pulseaudio"); pw_properties_set(props, PW_KEY_CLIENT_API, "pulseaudio");
if (p) if (p)
pw_properties_update(props, &p->props->dict); pw_properties_update_proplist(props, p);
loop = mainloop->userdata; loop = mainloop->userdata;
context = pw_context_new(loop, NULL, sizeof(struct pa_context)); context = pw_context_new(loop, NULL, sizeof(struct pa_context));

View file

@ -168,13 +168,11 @@ do { \
#define PA_FAIL_RETURN_NULL(context, error) \ #define PA_FAIL_RETURN_NULL(context, error) \
PA_FAIL_RETURN_ANY(context, error, NULL) 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_props(struct pw_properties *props);
pa_proplist* pa_proplist_new_dict(struct spa_dict *dict); pa_proplist* pa_proplist_new_dict(struct spa_dict *dict);
int pa_proplist_update_dict(pa_proplist *p, 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 pa_io_event {
struct spa_source *source; struct spa_source *source;

View file

@ -29,18 +29,27 @@
#include "internal.h" #include "internal.h"
#include "strbuf.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* pa_proplist_new_dict(struct spa_dict *dict)
{ {
pa_proplist *p; pa_proplist *p;
p = calloc(1, sizeof(struct pa_proplist)); p = pa_proplist_new();
if (p == NULL) if (p == NULL)
return NULL; return NULL;
if (dict) pa_proplist_update_dict(p, dict);
p->props = pw_properties_new_dict(dict);
else
p->props = pw_properties_new(NULL, NULL);
return p; return p;
} }
@ -52,14 +61,16 @@ pa_proplist* pa_proplist_new_props(struct pw_properties *props)
SPA_EXPORT SPA_EXPORT
pa_proplist* pa_proplist_new(void) 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) p = calloc(1, sizeof(struct pa_proplist));
{ if (p == NULL)
return pw_properties_update(p->props, dict); return NULL;
}
p->props = pw_properties_new(NULL, NULL);
return p;
}
SPA_EXPORT SPA_EXPORT
void pa_proplist_free(pa_proplist* p) 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; 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;
}

View file

@ -622,7 +622,7 @@ static pa_stream* stream_new(pa_context *c, const char *name,
props = pw_properties_new(PW_KEY_CLIENT_API, "pulseaudio", props = pw_properties_new(PW_KEY_CLIENT_API, "pulseaudio",
NULL); NULL);
pw_properties_update(props, &s->proplist->props->dict); pw_properties_update_proplist(props, s->proplist);
s->refcount = 1; s->refcount = 1;
s->context = c; s->context = c;