pulse-server: remove the MONITOR flag

PulseAudio has separate namespaces for sources and sinks so we can reuse
the same id for the sink and its monitor.
This commit is contained in:
Wim Taymans 2022-01-17 10:25:26 +01:00
parent 48e83fc780
commit 6a2aea8e0a
2 changed files with 16 additions and 23 deletions

View file

@ -57,7 +57,6 @@
#define SCACHE_ENTRY_SIZE_MAX (1024*1024*16) #define SCACHE_ENTRY_SIZE_MAX (1024*1024*16)
#define INDEX_MASK 0xffffffu #define INDEX_MASK 0xffffffu
#define MONITOR_FLAG (1u << 24)
#define EXTENSION_FLAG (1u << 25) #define EXTENSION_FLAG (1u << 25)
#define MODULE_FLAG (1u << 26) #define MODULE_FLAG (1u << 26)

View file

@ -220,8 +220,6 @@ static int send_object_event(struct client *client, struct pw_manager_object *o,
res_id); res_id);
} }
if (pw_manager_object_is_source_or_monitor(o)) { if (pw_manager_object_is_source_or_monitor(o)) {
if (!pw_manager_object_is_source(o))
res_id |= MONITOR_FLAG;
mask = SUBSCRIPTION_MASK_SOURCE; mask = SUBSCRIPTION_MASK_SOURCE;
event = SUBSCRIPTION_EVENT_SOURCE; event = SUBSCRIPTION_EVENT_SOURCE;
} }
@ -636,7 +634,7 @@ static int reply_create_record_stream(struct stream *stream, struct pw_manager_o
name = pw_properties_get(peer->props, PW_KEY_NODE_NAME); name = pw_properties_get(peer->props, PW_KEY_NODE_NAME);
if (!pw_manager_object_is_source(peer)) { if (!pw_manager_object_is_source(peer)) {
size_t len = (name ? strlen(name) : 5) + 10; size_t len = (name ? strlen(name) : 5) + 10;
peer_id = peer->id | MONITOR_FLAG; peer_id = peer->id;
peer_name = tmp = alloca(len); peer_name = tmp = alloca(len);
snprintf(tmp, len, "%s.monitor", name ? name : "sink"); snprintf(tmp, len, "%s.monitor", name ? name : "sink");
} else { } else {
@ -1835,8 +1833,6 @@ static int do_create_record_stream(struct client *client, uint32_t command, uint
source_index = id; source_index = id;
} }
if (source_index != SPA_ID_INVALID && source_index != 0) { if (source_index != SPA_ID_INVALID && source_index != 0) {
if (source_index & MONITOR_FLAG)
source_index &= INDEX_MASK;
pw_properties_setf(props, pw_properties_setf(props,
PW_KEY_NODE_TARGET, "%u", source_index); PW_KEY_NODE_TARGET, "%u", source_index);
} else if (source_name != NULL) { } else if (source_name != NULL) {
@ -2232,6 +2228,7 @@ static struct pw_manager_object *find_device(struct client *client,
{ {
struct selector sel; struct selector sel;
bool monitor = false, find_default = false; bool monitor = false, find_default = false;
struct pw_manager_object *o;
if (name != NULL) { if (name != NULL) {
if (spa_streq(name, DEFAULT_MONITOR)) { if (spa_streq(name, DEFAULT_MONITOR)) {
@ -2259,23 +2256,14 @@ static struct pw_manager_object *find_device(struct client *client,
id = SPA_ID_INVALID; id = SPA_ID_INVALID;
} }
if (id != SPA_ID_INVALID) { if (name != NULL) {
if (id & MONITOR_FLAG) {
if (sink)
return NULL;
monitor = true;
id &= ~MONITOR_FLAG;
}
} else if (name != NULL) {
if (spa_strendswith(name, ".monitor")) { if (spa_strendswith(name, ".monitor")) {
name = strndupa(name, strlen(name)-8); name = strndupa(name, strlen(name)-8);
monitor = true; monitor = true;
} }
} else } else if (id == SPA_ID_INVALID)
return NULL; return NULL;
if (is_monitor)
*is_monitor = monitor;
spa_zero(sel); spa_zero(sel);
sel.type = sink ? sel.type = sink ?
@ -2285,7 +2273,15 @@ static struct pw_manager_object *find_device(struct client *client,
sel.key = PW_KEY_NODE_NAME; sel.key = PW_KEY_NODE_NAME;
sel.value = name; sel.value = name;
return select_object(client->manager, &sel); o = select_object(client->manager, &sel);
if (o != NULL) {
if (!sink && pw_manager_object_is_monitor(o))
monitor = true;
}
if (is_monitor)
*is_monitor = monitor;
return o;
} }
static void sample_play_ready(void *data, uint32_t index) static void sample_play_ready(void *data, uint32_t index)
@ -3204,7 +3200,7 @@ static int do_lookup(struct client *client, uint32_t command, uint32_t tag, stru
reply = reply_new(client, tag); reply = reply_new(client, tag);
message_put(reply, message_put(reply,
TAG_U32, is_monitor ? o->id | MONITOR_FLAG : o->id, TAG_U32, o->id,
TAG_INVALID); TAG_INVALID);
return client_queue_message(client, reply); return client_queue_message(client, reply);
@ -3568,7 +3564,7 @@ static int fill_sink_info(struct client *client, struct message *m,
TAG_U32, module_id, /* module index */ TAG_U32, module_id, /* module index */
TAG_CVOLUME, &dev_info.volume_info.volume, TAG_CVOLUME, &dev_info.volume_info.volume,
TAG_BOOLEAN, dev_info.volume_info.mute, TAG_BOOLEAN, dev_info.volume_info.mute,
TAG_U32, o->id | MONITOR_FLAG, /* monitor source */ TAG_U32, o->id, /* monitor source index */
TAG_STRING, monitor_name, /* monitor source name */ TAG_STRING, monitor_name, /* monitor source name */
TAG_USEC, 0LL, /* latency */ TAG_USEC, 0LL, /* latency */
TAG_STRING, "PipeWire", /* driver */ TAG_STRING, "PipeWire", /* driver */
@ -3763,7 +3759,7 @@ static int fill_source_info(struct client *client, struct message *m,
dev_info.ss.format = SPA_AUDIO_FORMAT_S16; dev_info.ss.format = SPA_AUDIO_FORMAT_S16;
message_put(m, message_put(m,
TAG_U32, is_monitor ? o->id | MONITOR_FLAG: o->id, /* source index */ TAG_U32, o->id, /* source index */
TAG_STRING, is_monitor ? monitor_name : name, TAG_STRING, is_monitor ? monitor_name : name,
TAG_STRING, is_monitor ? monitor_desc : desc, TAG_STRING, is_monitor ? monitor_desc : desc,
TAG_SAMPLE_SPEC, &dev_info.ss, TAG_SAMPLE_SPEC, &dev_info.ss,
@ -3958,8 +3954,6 @@ static int fill_source_output_info(struct client *client, struct message *m,
peer = find_linked(manager, o->id, PW_DIRECTION_INPUT); peer = find_linked(manager, o->id, PW_DIRECTION_INPUT);
if (peer && pw_manager_object_is_source_or_monitor(peer)) { if (peer && pw_manager_object_is_source_or_monitor(peer)) {
peer_id = peer->id; peer_id = peer->id;
if (!pw_manager_object_is_source(peer))
peer_id |= MONITOR_FLAG;
} else { } else {
peer_id = SPA_ID_INVALID; peer_id = SPA_ID_INVALID;
} }