media-session: sanitize device names as well

See #827
This commit is contained in:
Wim Taymans 2021-03-04 12:45:35 +01:00
parent 184bdbeb4c
commit 1642e5220f
3 changed files with 40 additions and 7 deletions

View file

@ -488,7 +488,7 @@ static int update_device_props(struct device *device)
{ {
struct pw_properties *p = device->props; struct pw_properties *p = device->props;
const char *s, *d; const char *s, *d;
char temp[32]; char temp[32], tmp[1024];
int i; int i;
s = pw_properties_get(p, SPA_KEY_DEVICE_NAME); s = pw_properties_get(p, SPA_KEY_DEVICE_NAME);
@ -500,7 +500,9 @@ static int update_device_props(struct device *device)
snprintf(temp, sizeof(temp), "%d", device->id); snprintf(temp, sizeof(temp), "%d", device->id);
s = temp; s = temp;
} }
pw_properties_setf(p, PW_KEY_DEVICE_NAME, "alsa_card.%s", s); pw_properties_set(p, PW_KEY_DEVICE_NAME,
sm_media_session_sanitize_name(tmp, sizeof(tmp),
'_', "alsa_card.%s", s));
for (i = 2; i <= 99; i++) { for (i = 2; i <= 99; i++) {
if ((d = pw_properties_get(p, PW_KEY_DEVICE_NAME)) == NULL) if ((d = pw_properties_get(p, PW_KEY_DEVICE_NAME)) == NULL)
@ -509,7 +511,9 @@ static int update_device_props(struct device *device)
if (alsa_find_device(device->impl, SPA_ID_INVALID, d) == NULL) if (alsa_find_device(device->impl, SPA_ID_INVALID, d) == NULL)
break; break;
pw_properties_setf(p, PW_KEY_DEVICE_NAME, "alsa_card.%s.%d", s, i); pw_properties_set(p, PW_KEY_DEVICE_NAME,
sm_media_session_sanitize_name(tmp, sizeof(tmp),
'_', "alsa_card.%s.%d", s, i));
} }
if (i == 99) if (i == 99)
return -EEXIST; return -EEXIST;

View file

@ -329,6 +329,30 @@ static struct device *bluez5_find_device(struct impl *impl, uint32_t id)
return NULL; return NULL;
} }
static int update_device_props(struct device *device)
{
struct pw_properties *p = device->props;
const char *s;
char temp[32], tmp[1024];
s = pw_properties_get(p, SPA_KEY_DEVICE_NAME);
if (s == NULL)
s = pw_properties_get(p, SPA_KEY_API_BLUEZ5_ADDRESS);
if (s == NULL)
s = pw_properties_get(p, SPA_KEY_DEVICE_DESCRIPTION);
if (s == NULL) {
snprintf(temp, sizeof(temp), "%d", device->id);
s = temp;
}
if (strstr(s, "bluez_card.") == s)
s += strlen("bluez_card.");
pw_properties_set(p, PW_KEY_DEVICE_NAME,
sm_media_session_sanitize_name(tmp, sizeof(tmp),
'_', "bluez_card.%s", s));
return 0;
}
static void bluez5_update_device(struct impl *impl, struct device *dev, static void bluez5_update_device(struct impl *impl, struct device *dev,
const struct spa_device_object_info *info) const struct spa_device_object_info *info)
{ {
@ -338,6 +362,7 @@ static void bluez5_update_device(struct impl *impl, struct device *dev,
spa_debug_dict(0, info->props); spa_debug_dict(0, info->props);
pw_properties_update(dev->props, info->props); pw_properties_update(dev->props, info->props);
update_device_props(dev);
} }
static void device_destroy(void *data) static void device_destroy(void *data)
@ -376,7 +401,6 @@ static const struct sm_object_events device_events = {
.update = device_update, .update = device_update,
}; };
static struct device *bluez5_create_device(struct impl *impl, uint32_t id, static struct device *bluez5_create_device(struct impl *impl, uint32_t id,
const struct spa_device_object_info *info) const struct spa_device_object_info *info)
{ {
@ -420,6 +444,7 @@ static struct device *bluez5_create_device(struct impl *impl, uint32_t id,
device->handle = handle; device->handle = handle;
device->device = iface; device->device = iface;
device->props = pw_properties_new_dict(info->props); device->props = pw_properties_new_dict(info->props);
update_device_props(device);
device->sdevice = sm_media_session_export_device(impl->session, device->sdevice = sm_media_session_export_device(impl->session,
&device->props->dict, device->device); &device->props->dict, device->device);
if (device->sdevice == NULL) { if (device->sdevice == NULL) {

View file

@ -294,7 +294,7 @@ static int v4l2_update_device_props(struct device *dev)
{ {
struct pw_properties *p = dev->props; struct pw_properties *p = dev->props;
const char *s, *d; const char *s, *d;
char temp[32]; char temp[32], tmp[1024];
int i; int i;
if ((s = pw_properties_get(p, SPA_KEY_DEVICE_NAME)) == NULL) { if ((s = pw_properties_get(p, SPA_KEY_DEVICE_NAME)) == NULL) {
@ -305,7 +305,9 @@ static int v4l2_update_device_props(struct device *dev)
} }
} }
} }
pw_properties_setf(p, PW_KEY_DEVICE_NAME, "v4l2_device.%s", s); pw_properties_set(p, PW_KEY_DEVICE_NAME,
sm_media_session_sanitize_name(tmp, sizeof(tmp),
'_', "v4l2_device.%s", s));
for (i = 2; i <= 99; i++) { for (i = 2; i <= 99; i++) {
if ((d = pw_properties_get(p, PW_KEY_DEVICE_NAME)) == NULL) if ((d = pw_properties_get(p, PW_KEY_DEVICE_NAME)) == NULL)
@ -314,7 +316,9 @@ static int v4l2_update_device_props(struct device *dev)
if (v4l2_find_device(dev->impl, SPA_ID_INVALID, d) == NULL) if (v4l2_find_device(dev->impl, SPA_ID_INVALID, d) == NULL)
break; break;
pw_properties_setf(p, PW_KEY_DEVICE_NAME, "v4l2_device.%s.%d", s, i); pw_properties_set(p, PW_KEY_DEVICE_NAME,
sm_media_session_sanitize_name(tmp, sizeof(tmp),
'_', "v4l2_device.%s.%d", s, i));
} }
if (i == 99) if (i == 99)
return -EEXIST; return -EEXIST;