mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-17 08:56:49 -05:00
media-session: sanitize description
Because we use the description as the JACK name, remove the : so that it looks somewhat ok in more cases.
This commit is contained in:
parent
60233e30a7
commit
aea79cd79c
5 changed files with 52 additions and 40 deletions
|
|
@ -203,27 +203,6 @@ static const struct sm_object_methods node_methods = {
|
||||||
.release = node_release,
|
.release = node_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static SPA_PRINTF_FUNC(4,5) char *sanitize_nick(char *name, int size,
|
|
||||||
char sub, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
char *p;
|
|
||||||
va_list varargs;
|
|
||||||
|
|
||||||
va_start(varargs, fmt);
|
|
||||||
if (vsnprintf(name, size, fmt, varargs) < 0)
|
|
||||||
return NULL;
|
|
||||||
va_end(varargs);
|
|
||||||
|
|
||||||
for (p = name; *p; p++) {
|
|
||||||
switch(*p) {
|
|
||||||
case ':':
|
|
||||||
*p = sub;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct node *alsa_create_node(struct device *device, uint32_t id,
|
static struct node *alsa_create_node(struct device *device, uint32_t id,
|
||||||
const struct spa_device_object_info *info)
|
const struct spa_device_object_info *info)
|
||||||
{
|
{
|
||||||
|
|
@ -231,7 +210,7 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
||||||
struct impl *impl = device->impl;
|
struct impl *impl = device->impl;
|
||||||
int res;
|
int res;
|
||||||
const char *dev, *subdev, *stream, *profile, *profile_desc, *rules;
|
const char *dev, *subdev, *stream, *profile, *profile_desc, *rules;
|
||||||
char name[1024];
|
char tmp[1024];
|
||||||
int i, priority;
|
int i, priority;
|
||||||
|
|
||||||
pw_log_debug("new node %u", id);
|
pw_log_debug("new node %u", id);
|
||||||
|
|
@ -312,7 +291,8 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
||||||
s = pw_properties_get(device->props, "alsa.card_name");
|
s = pw_properties_get(device->props, "alsa.card_name");
|
||||||
|
|
||||||
pw_properties_set(node->props, PW_KEY_NODE_NICK,
|
pw_properties_set(node->props, PW_KEY_NODE_NICK,
|
||||||
sanitize_nick(name, sizeof(name), ' ', "%s", s));
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s", s));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (pw_properties_get(node->props, SPA_KEY_NODE_NAME) == NULL) {
|
if (pw_properties_get(node->props, SPA_KEY_NODE_NAME) == NULL) {
|
||||||
|
|
@ -324,7 +304,7 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
||||||
devname += 10;
|
devname += 10;
|
||||||
|
|
||||||
pw_properties_set(node->props, SPA_KEY_NODE_NAME,
|
pw_properties_set(node->props, SPA_KEY_NODE_NAME,
|
||||||
sm_media_session_sanitize_name(name, sizeof(name),
|
sm_media_session_sanitize_name(tmp, sizeof(tmp),
|
||||||
'_', "%s.%s.%s",
|
'_', "%s.%s.%s",
|
||||||
node->direction == PW_DIRECTION_OUTPUT ?
|
node->direction == PW_DIRECTION_OUTPUT ?
|
||||||
"alsa_input" : "alsa_output", devname, profile));
|
"alsa_input" : "alsa_output", devname, profile));
|
||||||
|
|
@ -337,7 +317,7 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pw_properties_set(node->props, SPA_KEY_NODE_NAME,
|
pw_properties_set(node->props, SPA_KEY_NODE_NAME,
|
||||||
sm_media_session_sanitize_name(name, sizeof(name),
|
sm_media_session_sanitize_name(tmp, sizeof(tmp),
|
||||||
'_', "%s.%s.%s.%d",
|
'_', "%s.%s.%s.%d",
|
||||||
node->direction == PW_DIRECTION_OUTPUT ?
|
node->direction == PW_DIRECTION_OUTPUT ?
|
||||||
"alsa_input" : "alsa_output", devname, profile, i));
|
"alsa_input" : "alsa_output", devname, profile, i));
|
||||||
|
|
@ -356,17 +336,21 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
||||||
name = dev;
|
name = dev;
|
||||||
|
|
||||||
if (profile_desc != NULL) {
|
if (profile_desc != NULL) {
|
||||||
pw_properties_setf(node->props, PW_KEY_NODE_DESCRIPTION, "%s %s",
|
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION,
|
||||||
desc, profile_desc);
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s %s", desc, profile_desc));
|
||||||
} else if (strcmp(subdev, "0")) {
|
} else if (strcmp(subdev, "0")) {
|
||||||
pw_properties_setf(node->props, PW_KEY_NODE_DESCRIPTION, "%s (%s %s)",
|
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION,
|
||||||
desc, name, subdev);
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s (%s %s)", desc, name, subdev));
|
||||||
} else if (strcmp(dev, "0")) {
|
} else if (strcmp(dev, "0")) {
|
||||||
pw_properties_setf(node->props, PW_KEY_NODE_DESCRIPTION, "%s (%s)",
|
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION,
|
||||||
desc, name);
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s (%s)", desc, name));
|
||||||
} else {
|
} else {
|
||||||
pw_properties_setf(node->props, PW_KEY_NODE_DESCRIPTION, "%s",
|
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION,
|
||||||
desc);
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s", desc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ static struct node *bluez5_create_node(struct device *device, uint32_t id,
|
||||||
int res;
|
int res;
|
||||||
const char *prefix, *str, *profile, *rules;
|
const char *prefix, *str, *profile, *rules;
|
||||||
int priority;
|
int priority;
|
||||||
char name[1024];
|
char tmp[1024];
|
||||||
|
|
||||||
pw_log_debug("new node %u", id);
|
pw_log_debug("new node %u", id);
|
||||||
|
|
||||||
|
|
@ -160,7 +160,10 @@ static struct node *bluez5_create_node(struct device *device, uint32_t id,
|
||||||
str = "bluetooth-device";
|
str = "bluetooth-device";
|
||||||
|
|
||||||
pw_properties_setf(node->props, PW_KEY_DEVICE_ID, "%d", device->device_id);
|
pw_properties_setf(node->props, PW_KEY_DEVICE_ID, "%d", device->device_id);
|
||||||
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION, str);
|
|
||||||
|
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION,
|
||||||
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s", str));
|
||||||
|
|
||||||
profile = pw_properties_get(node->props, SPA_KEY_API_BLUEZ5_PROFILE);
|
profile = pw_properties_get(node->props, SPA_KEY_API_BLUEZ5_PROFILE);
|
||||||
if (profile == NULL)
|
if (profile == NULL)
|
||||||
|
|
@ -177,7 +180,7 @@ static struct node *bluez5_create_node(struct device *device, uint32_t id,
|
||||||
prefix = info->factory_name;
|
prefix = info->factory_name;
|
||||||
|
|
||||||
pw_properties_set(node->props, PW_KEY_NODE_NAME,
|
pw_properties_set(node->props, PW_KEY_NODE_NAME,
|
||||||
sm_media_session_sanitize_name(name, sizeof(name),
|
sm_media_session_sanitize_name(tmp, sizeof(tmp),
|
||||||
'_', "%s.%s.%s", prefix, str, profile));
|
'_', "%s.%s.%s", prefix, str, profile));
|
||||||
|
|
||||||
pw_properties_set(node->props, PW_KEY_FACTORY_NAME, info->factory_name);
|
pw_properties_set(node->props, PW_KEY_FACTORY_NAME, info->factory_name);
|
||||||
|
|
|
||||||
|
|
@ -1823,6 +1823,26 @@ char *sm_media_session_sanitize_name(char *name, int size, char sub, const char
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *sm_media_session_sanitize_description(char *name, int size, char sub, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
va_list varargs;
|
||||||
|
|
||||||
|
va_start(varargs, fmt);
|
||||||
|
if (vsnprintf(name, size, fmt, varargs) < 0)
|
||||||
|
return NULL;
|
||||||
|
va_end(varargs);
|
||||||
|
|
||||||
|
for (p = name; *p; p++) {
|
||||||
|
switch(*p) {
|
||||||
|
case ':':
|
||||||
|
*p = sub;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
static void monitor_core_done(void *data, uint32_t id, int seq)
|
static void monitor_core_done(void *data, uint32_t id, int seq)
|
||||||
{
|
{
|
||||||
struct impl *impl = data;
|
struct impl *impl = data;
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,8 @@ int sm_media_session_match_rules(const char *rules, size_t size,
|
||||||
|
|
||||||
char *sm_media_session_sanitize_name(char *name, int size, char sub,
|
char *sm_media_session_sanitize_name(char *name, int size, char sub,
|
||||||
const char *fmt, ...) SPA_PRINTF_FUNC(4, 5);
|
const char *fmt, ...) SPA_PRINTF_FUNC(4, 5);
|
||||||
|
char *sm_media_session_sanitize_description(char *name, int size, char sub,
|
||||||
|
const char *fmt, ...) SPA_PRINTF_FUNC(4, 5);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
|
||||||
struct impl *impl = dev->impl;
|
struct impl *impl = dev->impl;
|
||||||
int i, res;
|
int i, res;
|
||||||
const char *prefix, *str, *d, *rules;
|
const char *prefix, *str, *d, *rules;
|
||||||
char name[1024];
|
char tmp[1024];
|
||||||
|
|
||||||
pw_log_debug("new node %u", id);
|
pw_log_debug("new node %u", id);
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
|
||||||
prefix = info->factory_name;
|
prefix = info->factory_name;
|
||||||
|
|
||||||
pw_properties_set(node->props, PW_KEY_NODE_NAME,
|
pw_properties_set(node->props, PW_KEY_NODE_NAME,
|
||||||
sm_media_session_sanitize_name(name, sizeof(name),
|
sm_media_session_sanitize_name(tmp, sizeof(tmp),
|
||||||
'_', "%s.%s", prefix, str));
|
'_', "%s.%s", prefix, str));
|
||||||
for (i = 2; i <= 99; i++) {
|
for (i = 2; i <= 99; i++) {
|
||||||
if ((d = pw_properties_get(node->props, PW_KEY_NODE_NAME)) == NULL)
|
if ((d = pw_properties_get(node->props, PW_KEY_NODE_NAME)) == NULL)
|
||||||
|
|
@ -174,14 +174,17 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pw_properties_set(node->props, PW_KEY_NODE_NAME,
|
pw_properties_set(node->props, PW_KEY_NODE_NAME,
|
||||||
sm_media_session_sanitize_name(name, sizeof(name),
|
sm_media_session_sanitize_name(tmp, sizeof(tmp),
|
||||||
'_', "%s.%s.%d", prefix, str, i));
|
'_', "%s.%s.%d", prefix, str, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
str = pw_properties_get(dev->props, SPA_KEY_DEVICE_DESCRIPTION);
|
str = pw_properties_get(dev->props, SPA_KEY_DEVICE_DESCRIPTION);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
str = "v4l2-device";
|
str = "v4l2-device";
|
||||||
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION, str);
|
|
||||||
|
pw_properties_set(node->props, PW_KEY_NODE_DESCRIPTION,
|
||||||
|
sm_media_session_sanitize_description(tmp, sizeof(tmp),
|
||||||
|
' ', "%s", str));
|
||||||
|
|
||||||
pw_properties_set(node->props, PW_KEY_FACTORY_NAME, info->factory_name);
|
pw_properties_set(node->props, PW_KEY_FACTORY_NAME, info->factory_name);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue