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;

View file

@ -212,14 +212,14 @@ static struct bluez5_object *bluez5_find_object(struct monitor *monitor, uint32_
}
static void bluez5_update_object(struct monitor *monitor, struct bluez5_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);
}
static struct bluez5_object *bluez5_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;
@ -303,8 +303,8 @@ static void bluez5_remove_object(struct monitor *monitor, struct bluez5_object *
free(obj);
}
static int bluez5_monitor_object_info(void *data, uint32_t id,
const struct spa_monitor_object_info *info)
static void bluez5_enum_object_info(void *data, uint32_t id,
const struct spa_device_object_info *info)
{
struct monitor *monitor = data;
struct bluez5_object *obj;
@ -313,21 +313,20 @@ static int bluez5_monitor_object_info(void *data, uint32_t id,
if (info == NULL) {
if (obj == NULL)
return -ENODEV;
return;
bluez5_remove_object(monitor, obj);
} else if (obj == NULL) {
if ((obj = bluez5_create_object(monitor, id, info)) == NULL)
return -ENOMEM;
return;
} else {
bluez5_update_object(monitor, obj, info);
}
return 0;
}
static const struct spa_monitor_callbacks bluez5_monitor_callbacks =
static const struct spa_device_events bluez5_enum_callbacks =
{
SPA_VERSION_MONITOR_CALLBACKS,
.object_info = bluez5_monitor_object_info,
SPA_VERSION_DEVICE_EVENTS,
.object_info = bluez5_enum_object_info,
};
static int bluez5_start_monitor(struct impl *impl, struct monitor *monitor)
@ -337,14 +336,14 @@ static int bluez5_start_monitor(struct impl *impl, struct monitor *monitor)
int res;
void *iface;
handle = pw_core_load_spa_handle(core, SPA_NAME_API_BLUEZ5_MONITOR, NULL);
handle = pw_core_load_spa_handle(core, SPA_NAME_API_BLUEZ5_ENUM_DBUS, 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 Device interface: %d", res);
goto out_unload;
}
@ -353,7 +352,8 @@ static int bluez5_start_monitor(struct impl *impl, struct monitor *monitor)
monitor->monitor = iface;
spa_list_init(&monitor->object_list);
spa_monitor_set_callbacks(monitor->monitor, &bluez5_monitor_callbacks, monitor);
spa_device_add_listener(monitor->monitor, &monitor->listener,
&bluez5_enum_callbacks, monitor);
return 0;

View file

@ -64,7 +64,7 @@ struct object {
struct spa_handle *handle;
struct pw_proxy *proxy;
struct spa_device *device;
struct spa_hook device_listener;
struct spa_hook listener;
struct spa_list node_list;
};
@ -78,11 +78,11 @@ struct impl {
struct pw_remote *remote;
struct spa_hook remote_listener;
struct spa_handle *monitor_handle;
struct spa_monitor *monitor;
struct spa_hook monitor_listener;
struct spa_handle *handle;
struct spa_device *device;
struct spa_hook listener;
struct spa_list object_list;
struct spa_list device_list;
};
static struct node *find_node(struct object *obj, uint32_t id)
@ -199,7 +199,7 @@ static struct object *find_object(struct impl *impl, uint32_t id)
{
struct object *obj;
spa_list_for_each(obj, &impl->object_list, link) {
spa_list_for_each(obj, &impl->device_list, link) {
if (obj->id == id)
return obj;
}
@ -207,14 +207,14 @@ static struct object *find_object(struct impl *impl, uint32_t id)
}
static void update_object(struct impl *impl, struct 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);
}
static struct object *create_object(struct impl *impl, uint32_t id,
const struct spa_monitor_object_info *info)
const struct spa_device_object_info *info)
{
struct pw_core *core = impl->core;
struct object *obj;
@ -256,9 +256,9 @@ static struct object *create_object(struct impl *impl, uint32_t id,
spa_list_init(&obj->node_list);
spa_device_add_listener(obj->device,
&obj->device_listener, &device_events, obj);
&obj->listener, &device_events, obj);
spa_list_append(&impl->object_list, &obj->link);
spa_list_append(&impl->device_list, &obj->link);
update_object(impl, obj, info);
@ -276,14 +276,14 @@ static void remove_object(struct impl *impl, struct object *obj)
{
pw_log_debug("remove object %u", obj->id);
spa_list_remove(&obj->link);
spa_hook_remove(&obj->device_listener);
spa_hook_remove(&obj->listener);
pw_proxy_destroy(obj->proxy);
free(obj->handle);
free(obj);
}
static int monitor_object_info(void *data, uint32_t id,
const struct spa_monitor_object_info *info)
static void dbus_device_object_info(void *data, uint32_t id,
const struct spa_device_object_info *info)
{
struct impl *impl = data;
struct object *obj;
@ -292,21 +292,20 @@ static int monitor_object_info(void *data, uint32_t id,
if (info == NULL) {
if (obj == NULL)
return -ENODEV;
return;
remove_object(impl, obj);
} else if (obj == NULL) {
if ((obj = create_object(impl, id, info)) == NULL)
return -ENOMEM;
return;
} else {
update_object(impl, obj, info);
}
return 0;
}
static const struct spa_monitor_callbacks monitor_callbacks =
static const struct spa_device_events dbus_device_events =
{
SPA_VERSION_MONITOR_CALLBACKS,
.object_info = monitor_object_info,
SPA_VERSION_DEVICE_EVENTS,
.object_info = dbus_device_object_info,
};
static int start_monitor(struct impl *impl)
@ -315,21 +314,21 @@ static int start_monitor(struct impl *impl)
int res;
void *iface;
handle = pw_core_load_spa_handle(impl->core, SPA_NAME_API_BLUEZ5_MONITOR, NULL);
handle = pw_core_load_spa_handle(impl->core, SPA_NAME_API_BLUEZ5_ENUM_DBUS, NULL);
if (handle == NULL) {
res = -errno;
goto out;
}
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %d", res);
goto out_unload;
}
impl->monitor_handle = handle;
impl->monitor = iface;
impl->handle = handle;
impl->device = iface;
spa_monitor_set_callbacks(impl->monitor, &monitor_callbacks, impl);
spa_device_add_listener(impl->device, &impl->listener, &dbus_device_events, impl);
return 0;
@ -390,7 +389,7 @@ int main(int argc, char *argv[])
clock_gettime(CLOCK_MONOTONIC, &impl.now);
spa_list_init(&impl.object_list);
spa_list_init(&impl.device_list);
pw_remote_add_listener(impl.remote,
&impl.remote_listener,

View file

@ -55,7 +55,9 @@ struct monitor {
struct impl *impl;
struct spa_handle *handle;
struct spa_monitor *monitor;
struct spa_device *monitor;
struct spa_hook listener;
struct spa_list object_list;
};

View file

@ -206,7 +206,7 @@ static struct v4l2_object *v4l2_find_object(struct monitor *monitor, uint32_t id
}
static void v4l2_update_object(struct monitor *monitor, struct v4l2_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);
@ -240,7 +240,7 @@ static int v4l2_update_device_props(struct v4l2_object *obj)
}
static struct v4l2_object *v4l2_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;
@ -318,8 +318,8 @@ static void v4l2_remove_object(struct monitor *monitor, struct v4l2_object *obj)
free(obj);
}
static int v4l2_monitor_object_info(void *data, uint32_t id,
const struct spa_monitor_object_info *info)
static void v4l2_udev_object_info(void *data, uint32_t id,
const struct spa_device_object_info *info)
{
struct monitor *monitor = data;
struct v4l2_object *obj;
@ -328,21 +328,20 @@ static int v4l2_monitor_object_info(void *data, uint32_t id,
if (info == NULL) {
if (obj == NULL)
return -ENODEV;
return;
v4l2_remove_object(monitor, obj);
} else if (obj == NULL) {
if ((obj = v4l2_create_object(monitor, id, info)) == NULL)
return -ENOMEM;
return;
} else {
v4l2_update_object(monitor, obj, info);
}
return 0;
}
static const struct spa_monitor_callbacks v4l2_monitor_callbacks =
static const struct spa_device_events v4l2_udev_callbacks =
{
SPA_VERSION_MONITOR_CALLBACKS,
.object_info = v4l2_monitor_object_info,
SPA_VERSION_DEVICE_EVENTS,
.object_info = v4l2_udev_object_info,
};
static int v4l2_start_monitor(struct impl *impl, struct monitor *monitor)
@ -352,13 +351,13 @@ static int v4l2_start_monitor(struct impl *impl, struct monitor *monitor)
int res;
void *iface;
handle = pw_core_load_spa_handle(core, SPA_NAME_API_V4L2_MONITOR, NULL);
handle = pw_core_load_spa_handle(core, SPA_NAME_API_V4L2_ENUM_UDEV, NULL);
if (handle == NULL) {
res = -errno;
goto out;
}
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %d", res);
goto out_unload;
}
@ -368,7 +367,8 @@ static int v4l2_start_monitor(struct impl *impl, struct monitor *monitor)
monitor->monitor = iface;
spa_list_init(&monitor->object_list);
spa_monitor_set_callbacks(monitor->monitor, &v4l2_monitor_callbacks, monitor);
spa_device_add_listener(monitor->monitor, &monitor->listener,
&v4l2_udev_callbacks, monitor);
return 0;