pulse-server: add stream/device state in dev_info

Also include and update the state of the device/stream in
collect_device_info so that we can compare it against the previous value
and emit a change event.

Fixes #3660
This commit is contained in:
Wim Taymans 2023-11-20 11:39:31 +01:00
parent 90bd9adb6b
commit 0c857f5455
3 changed files with 19 additions and 28 deletions

View file

@ -65,7 +65,7 @@ uint32_t id_to_index(struct pw_manager *m, uint32_t id)
return SPA_ID_INVALID; return SPA_ID_INVALID;
} }
bool collect_is_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction) static bool collect_is_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction)
{ {
struct pw_manager_object *o; struct pw_manager_object *o;
uint32_t in_node, out_node; uint32_t in_node, out_node;
@ -291,7 +291,7 @@ static void collect_device_info(struct pw_manager_object *device, struct pw_mana
} }
static void update_device_info(struct pw_manager *manager, struct pw_manager_object *o, static void update_device_info(struct pw_manager *manager, struct pw_manager_object *o,
enum pw_direction direction, bool monitor, struct defs *defs) enum pw_direction direction, bool monitor, struct defs *defs, bool stream)
{ {
const char *str; const char *str;
const char *key = monitor ? "device.info.monitor" : "device.info"; const char *key = monitor ? "device.info.monitor" : "device.info";
@ -313,6 +313,12 @@ static void update_device_info(struct pw_manager *manager, struct pw_manager_obj
} }
collect_device_info(o, card, &di, monitor, defs); collect_device_info(o, card, &di, monitor, defs);
di.state = node_state(info->state);
/* running sink/source that is not linked is reported as idle */
if (!stream && di.state == STATE_RUNNING &&
!collect_is_linked(manager, o->id, pw_direction_reverse(direction)))
di.state = STATE_IDLE;
dev_info = pw_manager_object_get_data(o, key); dev_info = pw_manager_object_get_data(o, key);
if (dev_info) { if (dev_info) {
if (memcmp(dev_info, &di, sizeof(di)) != 0) { if (memcmp(dev_info, &di, sizeof(di)) != 0) {
@ -586,16 +592,16 @@ void update_object_info(struct pw_manager *manager, struct pw_manager_object *o,
struct defs *defs) struct defs *defs)
{ {
if (pw_manager_object_is_sink(o)) { if (pw_manager_object_is_sink(o)) {
update_device_info(manager, o, PW_DIRECTION_OUTPUT, false, defs); update_device_info(manager, o, PW_DIRECTION_OUTPUT, false, defs, false);
update_device_info(manager, o, PW_DIRECTION_OUTPUT, true, defs); update_device_info(manager, o, PW_DIRECTION_OUTPUT, true, defs, false);
} }
if (pw_manager_object_is_source(o)) { if (pw_manager_object_is_source(o)) {
update_device_info(manager, o, PW_DIRECTION_INPUT, false, defs); update_device_info(manager, o, PW_DIRECTION_INPUT, false, defs, false);
} }
if (pw_manager_object_is_source_output(o)) { if (pw_manager_object_is_source_output(o)) {
update_device_info(manager, o, PW_DIRECTION_INPUT, false, defs); update_device_info(manager, o, PW_DIRECTION_INPUT, false, defs, true);
} }
if (pw_manager_object_is_sink_input(o)) { if (pw_manager_object_is_sink_input(o)) {
update_device_info(manager, o, PW_DIRECTION_OUTPUT, false, defs); update_device_info(manager, o, PW_DIRECTION_OUTPUT, false, defs, true);
} }
} }

View file

@ -42,6 +42,7 @@ void update_object_info(struct pw_manager *manager, struct pw_manager_object *o,
struct device_info { struct device_info {
uint32_t direction; uint32_t direction;
int state;
struct sample_spec ss; struct sample_spec ss;
struct channel_map map; struct channel_map map;
@ -59,6 +60,7 @@ struct device_info {
#define DEVICE_INFO_INIT(_dir) \ #define DEVICE_INFO_INIT(_dir) \
(struct device_info) { \ (struct device_info) { \
.direction = _dir, \ .direction = _dir, \
.state = STATE_INIT, \
.ss = SAMPLE_SPEC_INIT, \ .ss = SAMPLE_SPEC_INIT, \
.map = CHANNEL_MAP_INIT, \ .map = CHANNEL_MAP_INIT, \
.volume_info = VOLUME_INFO_INIT, \ .volume_info = VOLUME_INFO_INIT, \
@ -146,6 +148,5 @@ uint32_t find_port_index(struct pw_manager_object *card, uint32_t direction, con
struct pw_manager_object *find_peer_for_link(struct pw_manager *m, struct pw_manager_object *find_peer_for_link(struct pw_manager *m,
struct pw_manager_object *o, uint32_t id, enum pw_direction direction); struct pw_manager_object *o, uint32_t id, enum pw_direction direction);
struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction); struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction);
bool collect_is_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction);
#endif #endif

View file

@ -3770,17 +3770,9 @@ static int fill_sink_info(struct client *client, struct message *m,
TAG_INVALID); TAG_INVALID);
} }
if (client->version >= 15) { if (client->version >= 15) {
bool is_linked = collect_is_linked(manager, o->id, SPA_DIRECTION_INPUT);
int state = node_state(info->state);
/* running with nothing linked is probably the monitor that is
* keeping this sink busy */
if (state == STATE_RUNNING && !is_linked)
state = STATE_IDLE;
message_put(m, message_put(m,
TAG_VOLUME, dev_info.volume_info.base, /* base volume */ TAG_VOLUME, dev_info.volume_info.base, /* base volume */
TAG_U32, state, /* state */ TAG_U32, dev_info.state, /* state */
TAG_U32, dev_info.volume_info.steps, /* n_volume_steps */ TAG_U32, dev_info.volume_info.steps, /* n_volume_steps */
TAG_U32, card ? card->index : SPA_ID_INVALID, /* card index */ TAG_U32, card ? card->index : SPA_ID_INVALID, /* card index */
TAG_INVALID); TAG_INVALID);
@ -3974,17 +3966,9 @@ static int fill_source_info(struct client *client, struct message *m,
TAG_INVALID); TAG_INVALID);
} }
if (client->version >= 15) { if (client->version >= 15) {
bool is_linked = collect_is_linked(manager, o->id, SPA_DIRECTION_OUTPUT);
int state = node_state(info->state);
/* running with nothing linked is probably the sink that is
* keeping this source busy */
if (state == STATE_RUNNING && !is_linked)
state = STATE_IDLE;
message_put(m, message_put(m,
TAG_VOLUME, dev_info.volume_info.base, /* base volume */ TAG_VOLUME, dev_info.volume_info.base, /* base volume */
TAG_U32, state, /* state */ TAG_U32, dev_info.state, /* state */
TAG_U32, dev_info.volume_info.steps, /* n_volume_steps */ TAG_U32, dev_info.volume_info.steps, /* n_volume_steps */
TAG_U32, card ? card->index : SPA_ID_INVALID, /* card index */ TAG_U32, card ? card->index : SPA_ID_INVALID, /* card index */
TAG_INVALID); TAG_INVALID);
@ -4104,7 +4088,7 @@ static int fill_sink_input_info(struct client *client, struct message *m,
TAG_INVALID); TAG_INVALID);
if (client->version >= 19) if (client->version >= 19)
message_put(m, message_put(m,
TAG_BOOLEAN, info->state != PW_NODE_STATE_RUNNING, /* corked */ TAG_BOOLEAN, dev_info.state != STATE_RUNNING, /* corked */
TAG_INVALID); TAG_INVALID);
if (client->version >= 20) if (client->version >= 20)
message_put(m, message_put(m,
@ -4178,7 +4162,7 @@ static int fill_source_output_info(struct client *client, struct message *m,
TAG_INVALID); TAG_INVALID);
if (client->version >= 19) if (client->version >= 19)
message_put(m, message_put(m,
TAG_BOOLEAN, info->state != PW_NODE_STATE_RUNNING, /* corked */ TAG_BOOLEAN, dev_info.state != STATE_RUNNING, /* corked */
TAG_INVALID); TAG_INVALID);
if (client->version >= 22) { if (client->version >= 22) {
struct format_info fi; struct format_info fi;