diff --git a/src/modules/meson.build b/src/modules/meson.build index 69839f124..54612a8e2 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -223,7 +223,6 @@ pipewire_module_protocol_pulse_sources = [ 'module-protocol-pulse/extensions/ext-stream-restore.c', 'module-protocol-pulse/format.c', 'module-protocol-pulse/manager.c', - 'module-protocol-pulse/media-roles.c', 'module-protocol-pulse/message.c', 'module-protocol-pulse/message-handler.c', 'module-protocol-pulse/module.c', @@ -231,6 +230,7 @@ pipewire_module_protocol_pulse_sources = [ 'module-protocol-pulse/pending-sample.c', 'module-protocol-pulse/pulse-server.c', 'module-protocol-pulse/quirks.c', + 'module-protocol-pulse/remap.c', 'module-protocol-pulse/reply.c', 'module-protocol-pulse/sample.c', 'module-protocol-pulse/sample-play.c', diff --git a/src/modules/module-protocol-pulse/extensions/ext-device-restore.c b/src/modules/module-protocol-pulse/extensions/ext-device-restore.c index 25d6491bf..4fab65475 100644 --- a/src/modules/module-protocol-pulse/extensions/ext-device-restore.c +++ b/src/modules/module-protocol-pulse/extensions/ext-device-restore.c @@ -43,7 +43,6 @@ #include "../extension.h" #include "../format.h" #include "../manager.h" -#include "../media-roles.h" #include "../message.h" #include "../reply.h" #include "../volume.h" diff --git a/src/modules/module-protocol-pulse/extensions/ext-stream-restore.c b/src/modules/module-protocol-pulse/extensions/ext-stream-restore.c index dcccaca33..cb684cb3e 100644 --- a/src/modules/module-protocol-pulse/extensions/ext-stream-restore.c +++ b/src/modules/module-protocol-pulse/extensions/ext-stream-restore.c @@ -42,8 +42,8 @@ #include "../extension.h" #include "../format.h" #include "../manager.h" -#include "../media-roles.h" #include "../message.h" +#include "../remap.h" #include "../reply.h" #include "../volume.h" #include "registry.h" diff --git a/src/modules/module-protocol-pulse/message.c b/src/modules/module-protocol-pulse/message.c index 91413070d..f0d3d7e2f 100644 --- a/src/modules/module-protocol-pulse/message.c +++ b/src/modules/module-protocol-pulse/message.c @@ -28,15 +28,14 @@ #include #include #include -#include #include #include "defs.h" #include "format.h" #include "internal.h" #include "log.h" -#include "media-roles.h" #include "message.h" +#include "remap.h" #include "volume.h" #define MAX_SIZE (256*1024) @@ -65,20 +64,6 @@ static inline float volume_to_linear(uint32_t vol) return v * v * v; } -static 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" }, - { PW_KEY_DEVICE_INTENDED_ROLES, "device.intended_roles" }, - { PW_KEY_NODE_DESCRIPTION, "device.description" }, - { PW_KEY_MEDIA_ICON_NAME, "media.icon_name" }, - { 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 int read_u8(struct message *m, uint8_t *val) { if (m->offset + 1 > m->length) @@ -153,7 +138,7 @@ static int read_props(struct message *m, struct pw_properties *props, bool remap TAG_INVALID)) < 0) return res; - if (remap && (map = str_map_find(key_table, NULL, key)) != NULL) { + if (remap && (map = str_map_find(props_key_map, NULL, key)) != NULL) { key = map->pw_str; if (map->child != NULL && (map = str_map_find(map->child, NULL, data)) != NULL) @@ -567,7 +552,7 @@ static void write_dict(struct message *m, struct spa_dict *dict, bool remap) int l; const struct str_map *map; - if (remap && (map = str_map_find(key_table, key, NULL)) != NULL) { + if (remap && (map = str_map_find(props_key_map, key, NULL)) != NULL) { key = map->pa_str; if (map->child != NULL && (map = str_map_find(map->child, val, NULL)) != NULL) diff --git a/src/modules/module-protocol-pulse/module.c b/src/modules/module-protocol-pulse/module.c index 2e86e8372..b07d36531 100644 --- a/src/modules/module-protocol-pulse/module.c +++ b/src/modules/module-protocol-pulse/module.c @@ -41,6 +41,7 @@ #include "internal.h" #include "log.h" #include "module.h" +#include "remap.h" static void on_module_unload(void *obj, void *data, int res, uint32_t index) { @@ -139,6 +140,7 @@ void module_args_add_props(struct pw_properties *props, const char *str) { char *s = strdup(str), *p = s, *e, f; const char *k, *v; + const struct str_map *map; while (*p) { e = strchr(p, '='); @@ -168,6 +170,13 @@ void module_args_add_props(struct pw_properties *props, const char *str) if (*e != '\0') p++; *e = '\0'; + + if ((map = str_map_find(props_key_map, NULL, k)) != NULL) { + k = map->pw_str; + if (map->child != NULL && + (map = str_map_find(map->child, NULL, v)) != NULL) + v = map->pw_str; + } pw_properties_set(props, k, v); } free(s); diff --git a/src/modules/module-protocol-pulse/media-roles.c b/src/modules/module-protocol-pulse/remap.c similarity index 69% rename from src/modules/module-protocol-pulse/media-roles.c rename to src/modules/module-protocol-pulse/remap.c index b1fada1c6..1ddd9e3a7 100644 --- a/src/modules/module-protocol-pulse/media-roles.c +++ b/src/modules/module-protocol-pulse/remap.c @@ -24,7 +24,9 @@ #include -#include "media-roles.h" +#include + +#include "remap.h" const struct str_map media_role_map[] = { { "Movie", "video", }, @@ -38,3 +40,17 @@ const struct str_map media_role_map[] = { { "Test", "test", }, { NULL, NULL }, }; + +const struct str_map props_key_map[] = { + { PW_KEY_DEVICE_BUS_PATH, "device.bus_path" }, + { PW_KEY_DEVICE_FORM_FACTOR, "device.form_factor" }, + { PW_KEY_DEVICE_ICON_NAME, "device.icon_name" }, + { PW_KEY_DEVICE_INTENDED_ROLES, "device.intended_roles" }, + { PW_KEY_NODE_DESCRIPTION, "device.description" }, + { PW_KEY_MEDIA_ICON_NAME, "media.icon_name" }, + { 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 }, +}; diff --git a/src/modules/module-protocol-pulse/media-roles.h b/src/modules/module-protocol-pulse/remap.h similarity index 92% rename from src/modules/module-protocol-pulse/media-roles.h rename to src/modules/module-protocol-pulse/remap.h index 59103b820..49cbdf2ff 100644 --- a/src/modules/module-protocol-pulse/media-roles.h +++ b/src/modules/module-protocol-pulse/remap.h @@ -22,8 +22,8 @@ * DEALINGS IN THE SOFTWARE. */ -#ifndef PULSE_SERVER_MEDIA_ROLES_H -#define PULSE_SERVER_MEDIA_ROLES_H +#ifndef PULSE_SERVER_REMAP_H +#define PULSE_SERVER_REMAP_H #include @@ -37,6 +37,8 @@ struct str_map { extern const struct str_map media_role_map[]; +extern const struct str_map props_key_map[]; + static inline const struct str_map *str_map_find(const struct str_map *map, const char *pw, const char *pa) { size_t i; @@ -47,4 +49,4 @@ static inline const struct str_map *str_map_find(const struct str_map *map, cons return NULL; } -#endif /* PULSE_SERVER_MEDIA_ROLES_H */ +#endif /* PULSE_SERVER_REMAP_H */