diff --git a/src/examples/media-session/alsa-monitor.c b/src/examples/media-session/alsa-monitor.c index 3f21bde4a..4a19ec8f8 100644 --- a/src/examples/media-session/alsa-monitor.c +++ b/src/examples/media-session/alsa-monitor.c @@ -134,13 +134,18 @@ struct impl { static int probe_device(struct device *device); -static struct node *alsa_find_node(struct device *device, uint32_t id) +static struct node *alsa_find_node(struct device *device, uint32_t id, const char *name) { struct node *node; + const char *str; spa_list_for_each(node, &device->node_list, link) { if (node->id == id) return node; + if (name != NULL && + (str = pw_properties_get(node->props, PW_KEY_NODE_NAME)) != NULL && + strcmp(name, str) == 0) + return node; } return NULL; } @@ -474,7 +479,7 @@ static void alsa_device_object_info(void *data, uint32_t id, struct device *device = data; struct node *node; - node = alsa_find_node(device, id); + node = alsa_find_node(device, id, NULL); if (info == NULL) { if (node == NULL) { @@ -502,7 +507,7 @@ static void alsa_device_event(void *data, const struct spa_event *event) SPA_EVENT_DEVICE_Props, SPA_POD_OPT_Pod(&props)) < 0) return; - if ((node = alsa_find_node(device, id)) == NULL) + if ((node = alsa_find_node(device, id, NULL)) == NULL) return; switch (type) { @@ -523,13 +528,18 @@ static const struct spa_device_events alsa_device_events = { .event = alsa_device_event, }; -static struct device *alsa_find_device(struct impl *impl, uint32_t id) +static struct device *alsa_find_device(struct impl *impl, uint32_t id, const char *name) { struct device *device; + const char *str; spa_list_for_each(device, &impl->device_list, link) { if (device->id == id) return device; + if (name != NULL && + (str = pw_properties_get(device->props, PW_KEY_DEVICE_NAME)) != NULL && + strcmp(str, name) == 0) + return device; } return NULL; } @@ -550,6 +560,7 @@ static int update_device_props(struct device *device) struct pw_properties *p = device->props; const char *s, *d; char temp[32]; + int i; s = pw_properties_get(p, SPA_KEY_DEVICE_NAME); if (s == NULL) @@ -562,6 +573,18 @@ static int update_device_props(struct device *device) } pw_properties_setf(p, PW_KEY_DEVICE_NAME, "alsa_card.%s", s); + for (i = 2; i <= 99; i++) { + if ((d = pw_properties_get(p, PW_KEY_DEVICE_NAME)) == NULL) + break; + + if (alsa_find_device(device->impl, SPA_ID_INVALID, d) == NULL) + break; + + pw_properties_setf(p, PW_KEY_DEVICE_NAME, "alsa_card.%s.%d", s, i); + } + if (i == 99) + return -EEXIST; + if (pw_properties_get(p, PW_KEY_DEVICE_DESCRIPTION) == NULL) { d = NULL; @@ -985,7 +1008,7 @@ static void alsa_udev_object_info(void *data, uint32_t id, struct impl *impl = data; struct device *device; - device = alsa_find_device(impl, id); + device = alsa_find_device(impl, id, NULL); if (info == NULL) { if (device == NULL) diff --git a/src/examples/media-session/v4l2-monitor.c b/src/examples/media-session/v4l2-monitor.c index 3f75887a2..787f046f3 100644 --- a/src/examples/media-session/v4l2-monitor.c +++ b/src/examples/media-session/v4l2-monitor.c @@ -90,13 +90,18 @@ struct impl { struct spa_list device_list; }; -static struct node *v4l2_find_node(struct device *dev, uint32_t id) +static struct node *v4l2_find_node(struct device *dev, uint32_t id, const char *name) { struct node *node; + const char *str; spa_list_for_each(node, &dev->node_list, link) { if (node->id == id) return node; + if (name != NULL && + (str = pw_properties_get(node->props, PW_KEY_NODE_NAME)) != NULL && + strcmp(name, str) == 0) + return node; } return NULL; } @@ -203,7 +208,7 @@ static void v4l2_device_object_info(void *data, uint32_t id, struct device *dev = data; struct node *node; - node = v4l2_find_node(dev, id); + node = v4l2_find_node(dev, id, NULL); if (info == NULL) { if (node == NULL) { @@ -224,13 +229,18 @@ static const struct spa_device_events v4l2_device_events = { .object_info = v4l2_device_object_info }; -static struct device *v4l2_find_device(struct impl *impl, uint32_t id) +static struct device *v4l2_find_device(struct impl *impl, uint32_t id, const char *name) { struct device *dev; + const char *str; spa_list_for_each(dev, &impl->device_list, link) { if (dev->id == id) return dev; + if (name != NULL && + (str = pw_properties_get(dev->props, PW_KEY_DEVICE_NAME)) != NULL && + strcmp(str, name) == 0) + return dev; } return NULL; } @@ -251,6 +261,7 @@ static int v4l2_update_device_props(struct device *dev) struct pw_properties *p = dev->props; const char *s, *d; char temp[32]; + int i; if ((s = pw_properties_get(p, SPA_KEY_DEVICE_NAME)) == NULL) { if ((s = pw_properties_get(p, SPA_KEY_DEVICE_BUS_ID)) == NULL) { @@ -262,6 +273,18 @@ static int v4l2_update_device_props(struct device *dev) } pw_properties_setf(p, PW_KEY_DEVICE_NAME, "v4l2_device.%s", s); + for (i = 2; i <= 99; i++) { + if ((d = pw_properties_get(p, PW_KEY_DEVICE_NAME)) == NULL) + break; + + if (v4l2_find_device(dev->impl, SPA_ID_INVALID, d) == NULL) + break; + + pw_properties_setf(p, PW_KEY_DEVICE_NAME, "v4l2_device.%s.%d", s, i); + } + if (i == 99) + return -EEXIST; + if (pw_properties_get(p, PW_KEY_DEVICE_DESCRIPTION) == NULL) { d = pw_properties_get(p, PW_KEY_DEVICE_PRODUCT_NAME); if (!d) @@ -425,7 +448,7 @@ static void v4l2_udev_object_info(void *data, uint32_t id, struct impl *impl = data; struct device *dev; - dev = v4l2_find_device(impl, id); + dev = v4l2_find_device(impl, id, NULL); if (info == NULL) { if (dev == NULL)