monitor: remove monitor API and use device

Remove the monitor API, we can use the device API for it. Make sure
we support creating devices (like alsa) from another device (udev).

Use new object.id to store the object id in the object properties. Use
the port.id/node.id etc to make relations to other objects.
This commit is contained in:
Wim Taymans 2019-09-20 13:04:14 +02:00
parent 818fb9e904
commit 6756a3c8fc
43 changed files with 474 additions and 1015 deletions

View file

@ -221,7 +221,7 @@ static struct alsa_object *alsa_find_object(struct monitor *monitor, uint32_t id
}
static void alsa_update_object(struct monitor *monitor, struct alsa_object *obj,
const struct spa_monitor_object_info *info)
const struct spa_device_object_info *info)
{
pw_log_debug("update object %u", obj->id);
spa_debug_dict(0, info->props);
@ -306,7 +306,7 @@ static int update_device_props(struct alsa_object *obj)
static struct alsa_object *alsa_create_object(struct monitor *monitor, uint32_t id,
const struct spa_monitor_object_info *info)
const struct spa_device_object_info *info)
{
struct impl *impl = monitor->impl;
struct pw_core *core = impl->core;
@ -384,8 +384,8 @@ static void alsa_remove_object(struct monitor *monitor, struct alsa_object *obj)
free(obj);
}
static int alsa_monitor_object_info(void *data, uint32_t id,
const struct spa_monitor_object_info *info)
static void alsa_udev_object_info(void *data, uint32_t id,
const struct spa_device_object_info *info)
{
struct monitor *monitor = data;
struct alsa_object *obj;
@ -394,21 +394,20 @@ static int alsa_monitor_object_info(void *data, uint32_t id,
if (info == NULL) {
if (obj == NULL)
return -ENODEV;
return;
alsa_remove_object(monitor, obj);
} else if (obj == NULL) {
if ((obj = alsa_create_object(monitor, id, info)) == NULL)
return -ENOMEM;
return;
} else {
alsa_update_object(monitor, obj, info);
}
return 0;
}
static const struct spa_monitor_callbacks alsa_monitor_callbacks =
static const struct spa_device_events alsa_udev_events =
{
SPA_VERSION_MONITOR_CALLBACKS,
.object_info = alsa_monitor_object_info,
SPA_VERSION_DEVICE_EVENTS,
.object_info = alsa_udev_object_info,
};
static int alsa_start_monitor(struct impl *impl, struct monitor *monitor)
@ -418,14 +417,14 @@ static int alsa_start_monitor(struct impl *impl, struct monitor *monitor)
int res;
void *iface;
handle = pw_core_load_spa_handle(core, SPA_NAME_API_ALSA_MONITOR, NULL);
handle = pw_core_load_spa_handle(core, SPA_NAME_API_ALSA_ENUM_UDEV, NULL);
if (handle == NULL) {
res = -errno;
goto out;
}
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %d", res);
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) {
pw_log_error("can't get udev Device interface: %d", res);
goto out_unload;
}
@ -434,7 +433,7 @@ static int alsa_start_monitor(struct impl *impl, struct monitor *monitor)
monitor->monitor = iface;
spa_list_init(&monitor->object_list);
spa_monitor_set_callbacks(monitor->monitor, &alsa_monitor_callbacks, monitor);
spa_device_add_listener(monitor->monitor, &monitor->listener, &alsa_udev_events, monitor);
return 0;