mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pulse-server: add support for proplist value conversion
This commit is contained in:
		
							parent
							
								
									573e2afd5e
								
							
						
					
					
						commit
						242cddd371
					
				
					 2 changed files with 51 additions and 59 deletions
				
			
		| 
						 | 
				
			
			@ -43,12 +43,26 @@ static inline float volume_to_linear(uint32_t vol)
 | 
			
		|||
	return v * v * v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct key_map {
 | 
			
		||||
	const char *pw_key;
 | 
			
		||||
	const char *pa_key;
 | 
			
		||||
struct str_map {
 | 
			
		||||
	const char *pw_str;
 | 
			
		||||
	const char *pa_str;
 | 
			
		||||
	const struct str_map *child;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const struct key_map key_table[] = {
 | 
			
		||||
const struct str_map media_role_map[] = {
 | 
			
		||||
	{ "Movie", "video", },
 | 
			
		||||
	{ "Music", "music", },
 | 
			
		||||
	{ "Game", "game", },
 | 
			
		||||
	{ "Notification", "event", },
 | 
			
		||||
	{ "Communication", "phone", },
 | 
			
		||||
	{ "Movie", "animation", },
 | 
			
		||||
	{ "Production", "production", },
 | 
			
		||||
	{ "Accessibility", "a11y", },
 | 
			
		||||
	{ "Test", "test", },
 | 
			
		||||
	{ NULL, NULL },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const struct str_map key_table[] = {
 | 
			
		||||
	{ PW_KEY_DEVICE_BUS_PATH, "device.bus_path" },
 | 
			
		||||
	{ PW_KEY_DEVICE_FORM_FACTOR, "device.form_factor" },
 | 
			
		||||
	{ PW_KEY_DEVICE_ICON_NAME, "device.icon_name" },
 | 
			
		||||
| 
						 | 
				
			
			@ -57,25 +71,18 @@ const struct key_map key_table[] = {
 | 
			
		|||
	{ PW_KEY_APP_ICON_NAME, "application.icon_name" },
 | 
			
		||||
	{ PW_KEY_APP_PROCESS_MACHINE_ID, "application.process.machine_id" },
 | 
			
		||||
	{ PW_KEY_APP_PROCESS_SESSION_ID, "application.process.session_id" },
 | 
			
		||||
	{ PW_KEY_MEDIA_ROLE, "media.role", media_role_map },
 | 
			
		||||
	{ NULL, NULL },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static inline const char *pa_key_to_pw(const char *key)
 | 
			
		||||
static inline const struct str_map *str_map_find(const struct str_map *map, const char *pw, const char *pa)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
	for (i = 0; i < SPA_N_ELEMENTS(key_table); i++)
 | 
			
		||||
		if (strcmp(key_table[i].pa_key, key) == 0)
 | 
			
		||||
			return key_table[i].pw_key;
 | 
			
		||||
	return key;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline const char *pw_key_to_pa(const char *key)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
	for (i = 0; i < SPA_N_ELEMENTS(key_table); i++)
 | 
			
		||||
		if (strcmp(key_table[i].pw_key, key) == 0)
 | 
			
		||||
			return key_table[i].pa_key;
 | 
			
		||||
	return key;
 | 
			
		||||
	for (i = 0; map[i].pw_str; i++)
 | 
			
		||||
		if ((pw && strcmp(map[i].pw_str, pw) == 0) ||
 | 
			
		||||
		    (pa && strcmp(map[i].pa_str, pa) == 0))
 | 
			
		||||
			return &map[i];
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct descriptor {
 | 
			
		||||
| 
						 | 
				
			
			@ -167,10 +174,11 @@ static int read_props(struct message *m, struct pw_properties *props)
 | 
			
		|||
	int res;
 | 
			
		||||
 | 
			
		||||
	while (true) {
 | 
			
		||||
		char *key;
 | 
			
		||||
		void *data;
 | 
			
		||||
		const char *key;
 | 
			
		||||
		const void *data;
 | 
			
		||||
		uint32_t length;
 | 
			
		||||
		size_t size;
 | 
			
		||||
		const struct str_map *map;
 | 
			
		||||
 | 
			
		||||
		if ((res = message_get(m,
 | 
			
		||||
				TAG_STRING, &key,
 | 
			
		||||
| 
						 | 
				
			
			@ -192,7 +200,13 @@ static int read_props(struct message *m, struct pw_properties *props)
 | 
			
		|||
				TAG_INVALID)) < 0)
 | 
			
		||||
			return res;
 | 
			
		||||
 | 
			
		||||
		pw_properties_set(props, pa_key_to_pw(key), data);
 | 
			
		||||
		if ((map = str_map_find(key_table, NULL, key)) != NULL) {
 | 
			
		||||
			key = map->pw_str;
 | 
			
		||||
			if (map->child != NULL &&
 | 
			
		||||
			    (map = str_map_find(map->child, NULL, data)) != NULL)
 | 
			
		||||
				data = map->pw_str;
 | 
			
		||||
		}
 | 
			
		||||
		pw_properties_set(props, key, data);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -539,10 +553,21 @@ static void write_dict(struct message *m, struct spa_dict *dict)
 | 
			
		|||
	write_8(m, TAG_PROPLIST);
 | 
			
		||||
	if (dict != NULL) {
 | 
			
		||||
		spa_dict_for_each(it, dict) {
 | 
			
		||||
			int l = strlen(it->value);
 | 
			
		||||
			write_string(m, pw_key_to_pa(it->key));
 | 
			
		||||
			write_u32(m, l+1);
 | 
			
		||||
			write_arbitrary(m, it->value, l+1);
 | 
			
		||||
			const char *key = it->key;
 | 
			
		||||
			const char *val = it->value;
 | 
			
		||||
			int l;
 | 
			
		||||
			const struct str_map *map;
 | 
			
		||||
 | 
			
		||||
			if ((map = str_map_find(key_table, key, NULL)) != NULL) {
 | 
			
		||||
				key = map->pa_str;
 | 
			
		||||
				if (map->child != NULL &&
 | 
			
		||||
				    (map = str_map_find(map->child, val, NULL)) != NULL)
 | 
			
		||||
					val = map->pa_str;
 | 
			
		||||
			}
 | 
			
		||||
			write_string(m, key);
 | 
			
		||||
			l = strlen(val) + 1;
 | 
			
		||||
			write_u32(m, l);
 | 
			
		||||
			write_arbitrary(m, val, l);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	write_string(m, NULL);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1461,36 +1461,6 @@ static const struct pw_stream_events stream_events =
 | 
			
		|||
	.drained = stream_drained,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void fix_stream_properties(struct stream *stream, struct pw_properties *props)
 | 
			
		||||
{
 | 
			
		||||
	const char *str;
 | 
			
		||||
 | 
			
		||||
	if ((str = pw_properties_get(props, PW_KEY_MEDIA_ROLE)) != NULL) {
 | 
			
		||||
		if (strcmp(str, "video") == 0)
 | 
			
		||||
			str = "Movie";
 | 
			
		||||
		else if (strcmp(str, "music") == 0)
 | 
			
		||||
			str = "Music";
 | 
			
		||||
		else if (strcmp(str, "game") == 0)
 | 
			
		||||
			str = "Game";
 | 
			
		||||
		else if (strcmp(str, "event") == 0)
 | 
			
		||||
			str = "Notification";
 | 
			
		||||
		else if (strcmp(str, "phone") == 0)
 | 
			
		||||
			str = "Communication";
 | 
			
		||||
		else if (strcmp(str, "animation") == 0)
 | 
			
		||||
			str = "Movie";
 | 
			
		||||
		else if (strcmp(str, "production") == 0)
 | 
			
		||||
			str = "Production";
 | 
			
		||||
		else if (strcmp(str, "a11y") == 0)
 | 
			
		||||
			str = "Accessibility";
 | 
			
		||||
		else if (strcmp(str, "test") == 0)
 | 
			
		||||
			str = "Test";
 | 
			
		||||
		else
 | 
			
		||||
			str = "Music";
 | 
			
		||||
 | 
			
		||||
		pw_properties_set(props, PW_KEY_MEDIA_ROLE, str);
 | 
			
		||||
        }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int do_create_playback_stream(struct client *client, uint32_t command, uint32_t tag, struct message *m)
 | 
			
		||||
{
 | 
			
		||||
	struct impl *impl = client->impl;
 | 
			
		||||
| 
						 | 
				
			
			@ -1677,7 +1647,6 @@ static int do_create_playback_stream(struct client *client, uint32_t command, ui
 | 
			
		|||
		pw_properties_setf(props,
 | 
			
		||||
				PW_KEY_NODE_TARGET, "%u", sink_index);
 | 
			
		||||
 | 
			
		||||
	fix_stream_properties(stream, props),
 | 
			
		||||
	stream->stream = pw_stream_new(client->core, name, props);
 | 
			
		||||
	props = NULL;
 | 
			
		||||
	if (stream->stream == NULL)
 | 
			
		||||
| 
						 | 
				
			
			@ -1912,7 +1881,6 @@ static int do_create_record_stream(struct client *client, uint32_t command, uint
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fix_stream_properties(stream, props),
 | 
			
		||||
	stream->stream = pw_stream_new(client->core, name, props);
 | 
			
		||||
	props = NULL;
 | 
			
		||||
	if (stream->stream == NULL)
 | 
			
		||||
| 
						 | 
				
			
			@ -2938,7 +2906,6 @@ static int do_update_proplist(struct client *client, uint32_t command, uint32_t
 | 
			
		|||
		if (stream == NULL || stream->type == STREAM_TYPE_UPLOAD)
 | 
			
		||||
			goto error_noentity;
 | 
			
		||||
 | 
			
		||||
		fix_stream_properties(stream, props);
 | 
			
		||||
		pw_stream_update_properties(stream->stream, &props->dict);
 | 
			
		||||
	} else {
 | 
			
		||||
		pw_core_update_properties(client->core, &props->dict);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue