monitor: remove enum_items

Make the monitor and device emit the info and items when the callbacks
are set. This makes it easier to implement the monitor because there
is much less state to keep around and invalidate etc.
Rework the monitors
Add bluez5 device
This commit is contained in:
Wim Taymans 2018-11-26 12:18:53 +01:00
parent 10d277ce03
commit 57e94f7bc4
15 changed files with 510 additions and 332 deletions

View file

@ -368,19 +368,6 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
spa_list_init(&impl->item_list);
for (index = 0;;) {
struct spa_pod *item;
uint8_t buffer[4096];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
int res;
if ((res = spa_monitor_enum_items(this->monitor, &index, &item, &b)) <= 0) {
if (res != 0)
pw_log_debug("spa_monitor_enum_items: %s\n", spa_strerror(res));
break;
}
add_item(this, item, 0);
}
spa_monitor_set_callbacks(this->monitor, &callbacks, impl);
return this;

View file

@ -193,6 +193,12 @@ static const struct pw_node_events node_events = {
};
static void device_info(void *data, const struct spa_dict *info)
{
struct pw_device *device = data;
pw_device_update_properties(device, info);
}
static void device_add(void *data, uint32_t id,
const struct spa_handle_factory *factory, uint32_t type,
const struct spa_dict *info)
@ -228,6 +234,7 @@ static void device_add(void *data, uint32_t id,
nd->id = id;
nd->node = node;
nd->handle = SPA_MEMBER(nd, sizeof(struct node_data), void);
pw_node_add_listener(node, &nd->node_listener, &node_events, nd);
spa_list_append(&device->node_list, &nd->link);
if ((res = spa_handle_factory_init(factory,
@ -244,8 +251,6 @@ static void device_add(void *data, uint32_t id,
goto error;;
}
pw_node_add_listener(node, &nd->node_listener, &node_events, nd);
pw_node_set_implementation(node, iface);
pw_node_register(node, NULL, device->global, NULL);
pw_node_set_active(node, true);
@ -281,6 +286,7 @@ static void device_remove(void *data, uint32_t id)
static const struct spa_device_callbacks device_callbacks = {
SPA_VERSION_DEVICE_CALLBACKS,
.info = device_info,
.add = device_add,
.remove = device_remove,
};
@ -288,8 +294,6 @@ static const struct spa_device_callbacks device_callbacks = {
void pw_device_set_implementation(struct pw_device *device, struct spa_device *spa_device)
{
device->implementation = spa_device;
if (spa_device && spa_device->info)
pw_device_update_properties(device, spa_device->info);
spa_device_set_callbacks(device->implementation, &device_callbacks, device);
}

View file

@ -521,7 +521,7 @@ do_move_nodes(struct spa_loop *loop,
spa_graph_node_remove(&this->rt.root);
spa_graph_node_add(&dst->driver_graph, &this->rt.root);
if (spa_node_set_io(this->node,
if (this->node && spa_node_set_io(this->node,
SPA_IO_Position,
&dst->position, sizeof(struct spa_io_position)) >= 0) {
pw_log_debug("node %p: set position %p", this, &dst->position);
@ -770,6 +770,12 @@ int pw_node_update_properties(struct pw_node *node, const struct spa_dict *dict)
return changed;
}
static void node_info(void *data, const struct spa_dict *info)
{
struct pw_node *node = data;
pw_node_update_properties(node, info);
}
static void node_done(void *data, int seq, int res)
{
struct pw_node *node = data;
@ -860,6 +866,7 @@ static void node_reuse_buffer(void *data, uint32_t port_id, uint32_t buffer_id)
static const struct spa_node_callbacks node_callbacks = {
SPA_VERSION_NODE_CALLBACKS,
.info = node_info,
.done = node_done,
.event = node_event,
.process = node_process,