mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
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.
This commit is contained in:
parent
f2cc0e6723
commit
0b12cc96cc
5 changed files with 23 additions and 147 deletions
|
|
@ -984,18 +984,22 @@ static int metadata_property(void *object,
|
||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
struct global *global = object;
|
struct global *global = object;
|
||||||
int res;
|
pa_context *c = global->context;
|
||||||
|
uint32_t val;
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
if ((res = pa_metadata_update(global, subject, key, type, value)) < 0)
|
if (key && strcmp(key, METADATA_DEFAULT_SINK) == 0) {
|
||||||
return res;
|
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
|
||||||
|
changed = c->default_sink != val;
|
||||||
if (key) {
|
c->default_sink = val;
|
||||||
if (strcmp(key, METADATA_DEFAULT_SINK) == 0 ||
|
} else if (key && strcmp(key, METADATA_DEFAULT_SOURCE) == 0) {
|
||||||
strcmp(key, METADATA_DEFAULT_SOURCE) == 0) {
|
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
|
||||||
emit_event(global->context, global, PA_SUBSCRIPTION_EVENT_CHANGE);
|
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 = {
|
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->proplist = p ? pa_proplist_copy(p) : pa_proplist_new();
|
||||||
c->refcount = 1;
|
c->refcount = 1;
|
||||||
c->client_index = PA_INVALID_INDEX;
|
c->client_index = PA_INVALID_INDEX;
|
||||||
|
c->default_sink = SPA_ID_INVALID;
|
||||||
|
c->default_source = SPA_ID_INVALID;
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
|
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,8 @@ struct pa_context {
|
||||||
int disconnect:1;
|
int disconnect:1;
|
||||||
|
|
||||||
struct global *metadata;
|
struct global *metadata;
|
||||||
|
uint32_t default_sink;
|
||||||
|
uint32_t default_source;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct global *pa_context_find_global(pa_context *c, uint32_t id);
|
struct global *pa_context_find_global(pa_context *c, uint32_t id);
|
||||||
|
|
|
||||||
|
|
@ -1248,25 +1248,23 @@ struct server_data {
|
||||||
static const char *get_default_name(pa_context *c, uint32_t mask)
|
static const char *get_default_name(pa_context *c, uint32_t mask)
|
||||||
{
|
{
|
||||||
struct global *g;
|
struct global *g;
|
||||||
const char *str, *id = NULL, *type, *key;
|
const char *str;
|
||||||
|
uint32_t id = SPA_ID_INVALID;
|
||||||
|
|
||||||
if (c->metadata) {
|
if (c->metadata) {
|
||||||
if (mask & PA_SUBSCRIPTION_MASK_SINK)
|
if (mask & PA_SUBSCRIPTION_MASK_SINK)
|
||||||
key = METADATA_DEFAULT_SINK;
|
id = c->default_sink;
|
||||||
else if (mask & PA_SUBSCRIPTION_MASK_SOURCE)
|
else if (mask & PA_SUBSCRIPTION_MASK_SOURCE)
|
||||||
key = METADATA_DEFAULT_SOURCE;
|
id = c->default_source;
|
||||||
else
|
else
|
||||||
return NULL;
|
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) {
|
spa_list_for_each(g, &c->globals, link) {
|
||||||
if ((g->mask & mask) != mask)
|
if ((g->mask & mask) != mask)
|
||||||
continue;
|
continue;
|
||||||
if (g->props != NULL &&
|
if (g->props != NULL &&
|
||||||
(str = pw_properties_get(g->props, PW_KEY_NODE_NAME)) != 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 str;
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ pipewire_pulseaudio_sources = [
|
||||||
'json.c',
|
'json.c',
|
||||||
'mainloop.c',
|
'mainloop.c',
|
||||||
'mainloop-signal.c',
|
'mainloop-signal.c',
|
||||||
'metadata.c',
|
|
||||||
'operation.c',
|
'operation.c',
|
||||||
'proplist.c',
|
'proplist.c',
|
||||||
'rtclock.c',
|
'rtclock.c',
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue