From 7f38653589c0ead3e596ee86b2a75e1d618ba279 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 26 Jul 2024 15:13:40 +0200 Subject: [PATCH] filter: Use the stream DSP format to negotiate control types Add OSC and UMP control types and make sure the mixer converts to the selected format. Mostly useful for legacy filters that use the old MIDI format, placing the Midi control type in the format will make the mixer convert to it. --- src/pipewire/filter.c | 28 ++++++++++++++++++++-------- src/pipewire/stream.c | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index 23fc9cc59..4d878f584 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -1758,17 +1758,26 @@ static void add_video_dsp_port_params(struct filter *impl, struct port *port) SPA_FORMAT_VIDEO_format, SPA_POD_Id(SPA_VIDEO_FORMAT_DSP_F32))); } -static void add_control_dsp_port_params(struct filter *impl, struct port *port) +static void add_control_dsp_port_params(struct filter *impl, struct port *port, uint32_t types) { uint8_t buffer[4096]; struct spa_pod_builder b; + struct spa_pod_frame f[1]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); + spa_pod_builder_push_object(&b, &f[0], + SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat); + spa_pod_builder_add(&b, + SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_application), + SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_control), + 0); + if (types != 0) { + spa_pod_builder_add(&b, + SPA_FORMAT_CONTROL_types, SPA_POD_CHOICE_FLAGS_Int(types), + 0); + } add_param(impl, port, SPA_PARAM_EnumFormat, PARAM_FLAG_LOCKED, - spa_pod_builder_add_object(&b, - SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_application), - SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_control))); + spa_pod_builder_pop(&b, &f[0])); } SPA_EXPORT @@ -1824,9 +1833,12 @@ void *pw_filter_add_port(struct pw_filter *filter, add_audio_dsp_port_params(impl, p); else if (spa_streq(str, "32 bit float RGBA video")) add_video_dsp_port_params(impl, p); - else if (spa_streq(str, "8 bit raw midi") || - spa_streq(str, "8 bit raw control")) - add_control_dsp_port_params(impl, p); + else if (spa_streq(str, "8 bit raw midi")) + add_control_dsp_port_params(impl, p, 1u << SPA_CONTROL_Midi); + else if (spa_streq(str, "8 bit raw control")) + add_control_dsp_port_params(impl, p, 0); + else if (spa_streq(str, "32 bit raw UMP")) + add_control_dsp_port_params(impl, p, 1u << SPA_CONTROL_UMP); } /* then override with user provided if any */ if (update_params(impl, p, SPA_ID_INVALID, params, n_params) < 0) diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 93f63a5d0..04c04d32c 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1992,7 +1992,7 @@ pw_stream_connect(struct pw_stream *stream, pw_properties_set(impl->port_props, PW_KEY_FORMAT_DSP, str); else if (impl->media_type == SPA_MEDIA_TYPE_application && impl->media_subtype == SPA_MEDIA_SUBTYPE_control) - pw_properties_set(impl->port_props, PW_KEY_FORMAT_DSP, "8 bit raw midi"); + pw_properties_set(impl->port_props, PW_KEY_FORMAT_DSP, "32 bit raw UMP"); if (pw_properties_get(impl->port_props, PW_KEY_PORT_GROUP) == NULL) pw_properties_set(impl->port_props, PW_KEY_PORT_GROUP, "stream.0");