From 0833b19a75bfb126a7a381b4cd9765bd5568aaa3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 14 Nov 2024 11:07:05 +0100 Subject: [PATCH] module-vban: fill some default channel layouts VBAN does not really transmit any channel layouts so make some assumptions about the layout when not explicitly specified. --- src/modules/module-vban/stream.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/modules/module-vban/stream.c b/src/modules/module-vban/stream.c index 59ff351a4..d7d6b0a8d 100644 --- a/src/modules/module-vban/stream.c +++ b/src/modules/module-vban/stream.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -207,6 +208,30 @@ static uint32_t msec_to_samples(struct impl *impl, uint32_t msec) return msec * impl->rate / 1000; } +static const struct spa_audio_layout_info layouts[] = { + { SPA_AUDIO_LAYOUT_Mono }, + { SPA_AUDIO_LAYOUT_Stereo }, + { SPA_AUDIO_LAYOUT_2_1 }, + { SPA_AUDIO_LAYOUT_3_1 }, + { SPA_AUDIO_LAYOUT_5_0 }, + { SPA_AUDIO_LAYOUT_5_1 }, + { SPA_AUDIO_LAYOUT_7_0 }, + { SPA_AUDIO_LAYOUT_7_1 }, +}; + +static void default_layout(uint32_t channels, uint32_t *position) +{ + SPA_FOR_EACH_ELEMENT_VAR(layouts, l) { + if (l->n_channels == channels) { + for (uint32_t i = 0; i < l->n_channels; i++) + position[i] = l->position[i]; + return; + } + } + for (uint32_t i = 0; i < channels; i++) + position[i] = SPA_AUDIO_CHANNEL_AUX0 + i; +} + struct vban_stream *vban_stream_new(struct pw_core *core, enum pw_direction direction, struct pw_properties *props, const struct vban_stream_events *events, void *data) @@ -254,6 +279,8 @@ struct vban_stream *vban_stream_new(struct pw_core *core, switch (impl->info.media_subtype) { case SPA_MEDIA_SUBTYPE_raw: parse_audio_info(props, &impl->info.info.raw); + if (SPA_FLAG_IS_SET(impl->info.info.raw.flags, SPA_AUDIO_FLAG_UNPOSITIONED)) + default_layout(impl->info.info.raw.channels, impl->info.info.raw.position); impl->stream_info = impl->info; impl->format_info = find_audio_format_info(&impl->info); if (impl->format_info == NULL) {