diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-07-31 15:47:14 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-07-31 15:47:14 +0200 |
commit | 0b12cc96ccd8a687c0bd853cc9372a55f4bcb3a9 (patch) | |
tree | 106016356e87184e539b7dabd9a6886d020367cf | |
parent | f2cc0e67231c1cc00cba5846dc18f5824215fa57 (diff) |
pulse: remove metadata store
We don't actually need to store all the metadata, we just need to
track the default sink and source property and store the value.
-rw-r--r-- | pipewire-pulseaudio/src/context.c | 28 | ||||
-rw-r--r-- | pipewire-pulseaudio/src/internal.h | 2 | ||||
-rw-r--r-- | pipewire-pulseaudio/src/introspect.c | 12 | ||||
-rw-r--r-- | pipewire-pulseaudio/src/meson.build | 1 | ||||
-rw-r--r-- | pipewire-pulseaudio/src/metadata.c | 129 |
5 files changed, 24 insertions, 148 deletions
diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c index 4e646455..1c9f95a5 100644 --- a/pipewire-pulseaudio/src/context.c +++ b/pipewire-pulseaudio/src/context.c @@ -984,18 +984,22 @@ static int metadata_property(void *object, const char *value) { struct global *global = object; - int res; - - if ((res = pa_metadata_update(global, subject, key, type, value)) < 0) - return res; - - if (key) { - if (strcmp(key, METADATA_DEFAULT_SINK) == 0 || - strcmp(key, METADATA_DEFAULT_SOURCE) == 0) { - emit_event(global->context, global, PA_SUBSCRIPTION_EVENT_CHANGE); - } + pa_context *c = global->context; + uint32_t val; + bool changed = false; + + if (key && strcmp(key, METADATA_DEFAULT_SINK) == 0) { + val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; + changed = c->default_sink != val; + c->default_sink = val; + } else if (key && strcmp(key, METADATA_DEFAULT_SOURCE) == 0) { + val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; + changed = c->default_source != val; } - return res; + if (changed) + emit_event(global->context, global, PA_SUBSCRIPTION_EVENT_CHANGE); + + return 0; } static const struct pw_metadata_events metadata_events = { @@ -1413,6 +1417,8 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new(); c->refcount = 1; c->client_index = PA_INVALID_INDEX; + c->default_sink = SPA_ID_INVALID; + c->default_source = SPA_ID_INVALID; if (name) pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name); diff --git a/pipewire-pulseaudio/src/internal.h b/pipewire-pulseaudio/src/internal.h index 4cbb42ff..21847ce7 100644 --- a/pipewire-pulseaudio/src/internal.h +++ b/pipewire-pulseaudio/src/internal.h @@ -356,6 +356,8 @@ struct pa_context { int disconnect:1; struct global *metadata; + uint32_t default_sink; + uint32_t default_source; }; struct global *pa_context_find_global(pa_context *c, uint32_t id); diff --git a/pipewire-pulseaudio/src/introspect.c b/pipewire-pulseaudio/src/introspect.c index 5d2dafdc..c9c1e6d0 100644 --- a/pipewire-pulseaudio/src/introspect.c +++ b/pipewire-pulseaudio/src/introspect.c @@ -1248,25 +1248,23 @@ struct server_data { static const char *get_default_name(pa_context *c, uint32_t mask) { struct global *g; - const char *str, *id = NULL, *type, *key; + const char *str; + uint32_t id = SPA_ID_INVALID; if (c->metadata) { if (mask & PA_SUBSCRIPTION_MASK_SINK) - key = METADATA_DEFAULT_SINK; + id = c->default_sink; else if (mask & PA_SUBSCRIPTION_MASK_SOURCE) - key = METADATA_DEFAULT_SOURCE; + id = c->default_source; else return NULL; - - if (pa_metadata_get(c->metadata, PW_ID_CORE, key, &type, &id) <= 0) - id = NULL; } spa_list_for_each(g, &c->globals, link) { if ((g->mask & mask) != mask) continue; if (g->props != NULL && (str = pw_properties_get(g->props, PW_KEY_NODE_NAME)) != NULL && - (id == NULL || (uint32_t)atoi(id) == g->id)) + (id == SPA_ID_INVALID || id == g->id)) return str; } return "unknown"; diff --git a/pipewire-pulseaudio/src/meson.build b/pipewire-pulseaudio/src/meson.build index ebc2f04c..332824f6 100644 --- a/pipewire-pulseaudio/src/meson.build +++ b/pipewire-pulseaudio/src/meson.build @@ -13,7 +13,6 @@ pipewire_pulseaudio_sources = [ 'json.c', 'mainloop.c', 'mainloop-signal.c', - 'metadata.c', 'operation.c', 'proplist.c', 'rtclock.c', diff --git a/pipewire-pulseaudio/src/metadata.c b/pipewire-pulseaudio/src/metadata.c deleted file mode 100644 index 5fd858f3..00000000 --- a/pipewire-pulseaudio/src/metadata.c +++ /dev/null @@ -1,129 +0,0 @@ -/* PipeWire - * Copyright (C) 2020 Wim Taymans <wim.taymans@gmail.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include <errno.h> - -#include <spa/utils/result.h> - -#include "internal.h" - -struct metadata_item { - uint32_t subject; - char *key; - char *type; - char *value; -}; - -static void clear_item(struct metadata_item *it) -{ - free(it->key); - free(it->type); - free(it->value); -} - -void remove_all(struct global *global, uint32_t subject, const char *key) -{ - struct metadata_item *it; - for (it = pw_array_first(&global->metadata_info.metadata); - pw_array_check(&global->metadata_info.metadata, it);) { - if (it->subject == subject && - (key == NULL || it->key == NULL || strcmp(key, it->key) == 0)) { - clear_item(it); - pw_array_remove(&global->metadata_info.metadata, it); - } else { - it++; - } - } -} - -static struct metadata_item *find_item(struct global *global, uint32_t subject, - const char *key) -{ - struct metadata_item *it; - pw_array_for_each(it, &global->metadata_info.metadata) { - if (it->subject == subject && - (key == NULL || strcmp(key, it->key) == 0)) - return it; - } - return NULL; -} - -static int replace_item(struct metadata_item *it, const char *type, const char *value) -{ - if (it->type == NULL || strcmp(it->type, type) != 0) { - free(it->type); - it->type = strdup(type); - } - if (it->value == NULL || strcmp(it->value, value) != 0) { - free(it->value); - it->value = strdup(value); - } - return 0; -} - -static int add_item(struct global *global, uint32_t subject, const char *key, - const char *type, const char *value) -{ - struct metadata_item *it; - it = pw_array_add(&global->metadata_info.metadata, sizeof(*it)); - if (it == NULL) - return -errno; - it->subject = subject; - it->key = strdup(key); - it->type = strdup(type); - it->value = strdup(value); - return 0; -} - -int pa_metadata_update(struct global *global, uint32_t subject, const char *key, - const char *type, const char *value) -{ - struct metadata_item *it; - int res = 0; - pw_log_info("metadata %p: id:%u key:%s value:%s type:%s", - global, subject, key, value, type); - - if (key == NULL || value == NULL) { - remove_all(global, subject, key); - } else { - if (type == NULL) - type = ""; - it = find_item(global, subject, key); - if (it == NULL) { - res = add_item(global, subject, key, type, value); - } else { - res = replace_item(it, type, value); - } - } - return res; -} - -int pa_metadata_get(struct global *global, uint32_t subject, const char *key, - const char **type, const char **value) -{ - struct metadata_item *it; - it = find_item(global, subject, key); - if (it == NULL) - return 0; - if (type) - *type = it->type; - if (value) - *value = it->value; - return 1; -} |