pulse-server: improve GET_SERVER_INFO

We don't need to bind to the core object again, we can just use the
events on the manager core.
We don't actually have info when the Core is added so don't try to
use it to get defaults for the client.
Use the manager core info in server info.
This commit is contained in:
Wim Taymans 2020-11-05 10:36:13 +01:00
parent 5a98a9b1cd
commit b472abe65b
3 changed files with 28 additions and 31 deletions

View file

@ -136,12 +136,6 @@ static void object_destroy(struct object *o)
free(o);
}
/* core */
static const struct object_info core_info = {
.type = PW_TYPE_INTERFACE_Core,
.version = PW_VERSION_CORE,
};
/* client */
static void client_event_info(void *object, const struct pw_client_info *info)
{
@ -393,7 +387,6 @@ static const struct object_info metadata_info = {
static const struct object_info *objects[] =
{
&core_info,
&module_info,
&client_info,
&device_info,
@ -508,6 +501,12 @@ static const struct pw_registry_events registry_events = {
.global_remove = registry_event_global_remove,
};
static void on_core_info(void *data, const struct pw_core_info *info)
{
struct manager *m = data;
m->this.info = pw_core_info_update(m->this.info, info);
}
static void on_core_done(void *data, uint32_t id, int seq)
{
struct manager *m = data;
@ -532,6 +531,7 @@ static void on_core_done(void *data, uint32_t id, int seq)
static const struct pw_core_events core_events = {
PW_VERSION_CORE_EVENTS,
.done = on_core_done,
.info = on_core_info,
};
struct pw_manager *pw_manager_new(struct pw_core *core)
@ -621,6 +621,8 @@ void pw_manager_destroy(struct pw_manager *manager)
spa_list_consume(o, &m->this.object_list, this.link)
object_destroy(o);
if (m->this.info)
pw_core_info_free(m->this.info);
if (m->this.registry) {
spa_hook_remove(&m->registry_listener);
pw_proxy_destroy((struct pw_proxy*)m->this.registry);

View file

@ -58,6 +58,8 @@ struct pw_manager {
struct pw_core *core;
struct pw_registry *registry;
struct pw_core_info *info;
uint32_t n_objects;
struct spa_list object_list;
};

View file

@ -95,8 +95,6 @@ struct client {
struct pw_manager *manager;
struct spa_hook manager_listener;
uint32_t cookie;
uint32_t default_rate;
uint32_t subscribed;
uint32_t default_sink;
@ -559,19 +557,8 @@ static uint32_t get_event_and_id(struct client *client, struct pw_manager_object
static void manager_added(void *data, struct pw_manager_object *o)
{
struct client *client = data;
const char *str;
uint32_t event, id;
if (strcmp(o->type, PW_TYPE_INTERFACE_Core) == 0 && o->info != NULL) {
struct pw_core_info *info = o->info;
if (info->props &&
(str = spa_dict_lookup(info->props, "default.clock.rate")) != NULL)
client->default_rate = atoi(str);
client->cookie = info->cookie;
return;
}
if ((event = get_event_and_id(client, o, &id)) != SPA_ID_INVALID)
send_subscribe_event(client,
event | SUBSCRIPTION_EVENT_NEW,
@ -2614,25 +2601,31 @@ error_noentity:
static int do_get_server_info(struct client *client, uint32_t command, uint32_t tag, struct message *m)
{
struct impl *impl = client->impl;
struct pw_manager *manager = client->manager;
struct pw_core_info *info = manager->info;
char name[256];
const char *str;
struct message *reply;
struct sample_spec ss;
struct channel_map map;
uint32_t cookie;
pw_log_info(NAME" %p: GET_SERVER_INFO", impl);
ss = SAMPLE_SPEC_INIT;
map = CHANNEL_MAP_INIT;
if (manager->info != NULL) {
if (info->props &&
(str = spa_dict_lookup(info->props, "default.clock.rate")) != NULL)
ss.rate = atoi(str);
cookie = info->cookie;
} else {
cookie = 0;
}
snprintf(name, sizeof(name)-1, "PulseAudio (on PipeWire %s)", pw_get_library_version());
spa_zero(ss);
ss.format = SAMPLE_FLOAT32LE;
ss.rate = client->default_rate ? client->default_rate : 44100;
ss.channels = 2;
spa_zero(map);
map.channels = 2;
map.map[0] = 1;
map.map[1] = 2;
reply = reply_new(client, tag);
message_put(reply,
TAG_STRING, name,
@ -2642,7 +2635,7 @@ static int do_get_server_info(struct client *client, uint32_t command, uint32_t
TAG_SAMPLE_SPEC, &ss,
TAG_STRING, get_default(client, true), /* default sink name */
TAG_STRING, get_default(client, false), /* default source name */
TAG_U32, client->cookie, /* cookie */
TAG_U32, cookie, /* cookie */
TAG_INVALID);
if (client->version >= 15) {