From b5555cc3f650d534f80873a094f99defeb2ec897 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 12 Jun 2026 17:50:46 +0200 Subject: [PATCH] port-config: add internalFormat to PortConfig Use the Format for all possible formats on the EnumPortConfig and the configured external format on PortConfig. Make a new internalFormat that contains the configured format of the adapter follower. Make pw-top use the PortConfig internalFormat in the FORMAT view and fall back to Format, when not available (for older clients). --- spa/include/spa/param/port-config-types.h | 1 + spa/include/spa/param/port-config.h | 3 ++- spa/plugins/audioconvert/audioadapter.c | 15 ++++++++++----- spa/plugins/audioconvert/audioconvert.c | 2 +- src/tools/pw-top.c | 12 +++++++++--- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/spa/include/spa/param/port-config-types.h b/spa/include/spa/param/port-config-types.h index 9110b0022..42d49d209 100644 --- a/spa/include/spa/param/port-config-types.h +++ b/spa/include/spa/param/port-config-types.h @@ -40,6 +40,7 @@ static const struct spa_type_info spa_type_param_port_config[] = { { SPA_PARAM_PORT_CONFIG_control, SPA_TYPE_Bool, SPA_TYPE_INFO_PARAM_PORT_CONFIG_BASE "control", NULL }, { SPA_PARAM_PORT_CONFIG_format, SPA_TYPE_OBJECT_Format, SPA_TYPE_INFO_PARAM_PORT_CONFIG_BASE "format", NULL }, { SPA_PARAM_PORT_CONFIG_group, SPA_TYPE_String, SPA_TYPE_INFO_PARAM_PORT_CONFIG_BASE "group", NULL }, + { SPA_PARAM_PORT_CONFIG_internalFormat, SPA_TYPE_OBJECT_Format, SPA_TYPE_INFO_PARAM_PORT_CONFIG_BASE "internalFormat", NULL }, { 0, 0, NULL, NULL }, }; diff --git a/spa/include/spa/param/port-config.h b/spa/include/spa/param/port-config.h index e5a8d7533..686dd9099 100644 --- a/spa/include/spa/param/port-config.h +++ b/spa/include/spa/param/port-config.h @@ -32,8 +32,9 @@ enum spa_param_port_config { SPA_PARAM_PORT_CONFIG_mode, /**< (Id enum spa_param_port_config_mode) mode */ SPA_PARAM_PORT_CONFIG_monitor, /**< (Bool) enable monitor output ports on input ports */ SPA_PARAM_PORT_CONFIG_control, /**< (Bool) enable control ports */ - SPA_PARAM_PORT_CONFIG_format, /**< (Object) format filter */ + SPA_PARAM_PORT_CONFIG_format, /**< (Object) possible/external format configuration */ SPA_PARAM_PORT_CONFIG_group, /**< (String) the port group name */ + SPA_PARAM_PORT_CONFIG_internalFormat, /**< (Object) actual internal format */ }; /** diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index ee4d518ef..db95856a7 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -173,16 +173,20 @@ static int convert_enum_port_config(struct impl *this, { struct spa_pod *f1, *f2 = NULL, *format = NULL; struct spa_pod_frame f[1]; - uint32_t fmt_id, fmt_start = 0; + uint32_t fmt_id, fmt_start = 0, pc_id; int res; if (this->convert == NULL) return 0; - if (id == SPA_PARAM_EnumPortConfig) + if (id == SPA_PARAM_EnumPortConfig) { fmt_id = SPA_PARAM_EnumFormat; - else + pc_id = SPA_PARAM_PORT_CONFIG_format; + } + else { fmt_id = SPA_PARAM_Format; + pc_id = SPA_PARAM_PORT_CONFIG_internalFormat; + } res = spa_node_port_enum_params_sync(this->follower, this->direction, 0, @@ -195,7 +199,7 @@ static int convert_enum_port_config(struct impl *this, 0); if (res > 0) { spa_pod_builder_add(builder, - SPA_PARAM_PORT_CONFIG_format, SPA_POD_Pod(format), + pc_id, SPA_POD_Pod(format), 0); } f1 = spa_pod_builder_pop(builder, &f[0]); @@ -253,7 +257,8 @@ next: SPA_PARAM_PORT_CONFIG_direction, SPA_POD_Id(this->direction), SPA_PARAM_PORT_CONFIG_mode, SPA_POD_Id( SPA_PARAM_PORT_CONFIG_MODE_passthrough), - SPA_PARAM_PORT_CONFIG_format, SPA_POD_Pod(format)); + SPA_PARAM_PORT_CONFIG_format, SPA_POD_Pod(format), + SPA_PARAM_PORT_CONFIG_internalFormat, SPA_POD_Pod(format)); result.next++; res = 1; break; diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 889743787..812ce5ecd 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -558,7 +558,7 @@ static int node_param_port_config(struct impl *this, uint32_t id, uint32_t index } if (dir->have_format) { spa_pod_builder_prop(b, SPA_PARAM_PORT_CONFIG_format, 0); - spa_format_audio_raw_build(b, id, &dir->format.info.raw); + spa_format_audio_build(b, id, &dir->format); } *param = spa_pod_builder_pop(b, &f[0]); break; diff --git a/src/tools/pw-top.c b/src/tools/pw-top.c index 35b73d340..57ef2c7b2 100644 --- a/src/tools/pw-top.c +++ b/src/tools/pw-top.c @@ -326,14 +326,20 @@ static void node_param(void *data, int seq, struct node *n = data; switch (id) { + case SPA_PARAM_Format: + { + handle_format(n, param); + break; + } case SPA_PARAM_PortConfig: { const struct spa_pod *format = NULL; if (spa_pod_parse_object(param, SPA_TYPE_OBJECT_ParamPortConfig, NULL, - SPA_PARAM_PORT_CONFIG_format, SPA_POD_OPT_Pod(&format)) < 0) + SPA_PARAM_PORT_CONFIG_internalFormat, SPA_POD_OPT_Pod(&format)) < 0) return; - handle_format(n, format); + if (format != NULL) + handle_format(n, format); break; } default: @@ -361,7 +367,7 @@ static struct node *add_node(struct data *d, uint32_t id, const char *name) n->proxy = pw_registry_bind(d->registry, id, PW_TYPE_INTERFACE_Node, PW_VERSION_NODE, 0); if (n->proxy) { - uint32_t ids[] = { SPA_PARAM_PortConfig }; + uint32_t ids[] = { SPA_PARAM_Format, SPA_PARAM_PortConfig }; pw_proxy_add_listener(n->proxy, &n->proxy_listener, &proxy_events, n);