From 6d74eee874ac92d587050218bf7db95fefa4ef6a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 24 Oct 2025 08:53:21 +0200 Subject: [PATCH] spa: bump channels to 128 again Remove the SPA_AUDIO_MAX_POSITION define and use the SPA_AUDIO_MAX_CHANNELS again. Make a compile time define to override the default max channels of 64. Make sure we compile the SPA library with the default 64 channels. If you use the SPA library on a spa_audio_info you will get 64 channel support, like before. If you want more channels, you will need to make a padded structure or redefine the MAX_CHANNELS before you use the spa_audio_info structures. You can use the padded structure with the new functions that take the structure size. With the extra checks in the parsing code, we avoid making a valid spa_audio_info with too many channels that don't fit in the structure. This means that code that receives a spa_audio_info can assume there is enough padding for all the channels. --- meson.build | 1 + spa/include/spa/param/audio/dsd.h | 2 +- spa/include/spa/param/audio/layout.h | 2 +- spa/include/spa/param/audio/raw-json.h | 2 +- spa/include/spa/param/audio/raw.h | 20 +++++++++----------- spa/lib/lib.c | 8 ++------ 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/meson.build b/meson.build index e0a333a8f..e81ce8214 100644 --- a/meson.build +++ b/meson.build @@ -115,6 +115,7 @@ cc_flags = common_flags + [ '-Werror=old-style-definition', '-Werror=missing-parameter-type', '-Werror=strict-prototypes', + '-DSPA_AUDIO_MAX_CHANNELS=128u', ] add_project_arguments(cc.get_supported_arguments(cc_flags), language: 'c') diff --git a/spa/include/spa/param/audio/dsd.h b/spa/include/spa/param/audio/dsd.h index 733823780..73f3d4e8b 100644 --- a/spa/include/spa/param/audio/dsd.h +++ b/spa/include/spa/param/audio/dsd.h @@ -45,7 +45,7 @@ struct spa_audio_info_dsd { int32_t interleave; /*< interleave bytes */ uint32_t rate; /*< sample rate (in bytes per second) */ uint32_t channels; /*< channels */ - uint32_t position[SPA_AUDIO_MAX_POSITION]; /*< channel position from enum spa_audio_channel */ + uint32_t position[SPA_AUDIO_MAX_CHANNELS]; /*< channel position from enum spa_audio_channel */ }; #define SPA_AUDIO_INFO_DSD_INIT(...) ((struct spa_audio_info_dsd) { __VA_ARGS__ }) diff --git a/spa/include/spa/param/audio/layout.h b/spa/include/spa/param/audio/layout.h index e5e59caf9..19e3a3c42 100644 --- a/spa/include/spa/param/audio/layout.h +++ b/spa/include/spa/param/audio/layout.h @@ -20,7 +20,7 @@ extern "C" { struct spa_audio_layout_info { uint32_t n_channels; - uint32_t position[SPA_AUDIO_MAX_POSITION]; + uint32_t position[SPA_AUDIO_MAX_CHANNELS]; }; #define SPA_AUDIO_LAYOUT_Mono 1, { SPA_AUDIO_CHANNEL_MONO, } diff --git a/spa/include/spa/param/audio/raw-json.h b/spa/include/spa/param/audio/raw-json.h index 7c8c11ca3..c33a9310f 100644 --- a/spa/include/spa/param/audio/raw-json.h +++ b/spa/include/spa/param/audio/raw-json.h @@ -51,7 +51,7 @@ SPA_API_AUDIO_RAW_JSON int spa_audio_parse_position(const char *str, size_t len, uint32_t *position, uint32_t *n_channels) { - return spa_audio_parse_position_n(str, len, position, SPA_AUDIO_MAX_POSITION, n_channels); + return spa_audio_parse_position_n(str, len, position, SPA_AUDIO_MAX_CHANNELS, n_channels); } SPA_API_AUDIO_RAW_JSON int diff --git a/spa/include/spa/param/audio/raw.h b/spa/include/spa/param/audio/raw.h index 1688595e1..392b65daa 100644 --- a/spa/include/spa/param/audio/raw.h +++ b/spa/include/spa/param/audio/raw.h @@ -18,14 +18,10 @@ extern "C" { * \{ */ -/* This is the max number of position info, changing this will change the - * ABI */ -#define SPA_AUDIO_MAX_POSITION 64u - -/* The suggested number of max channels, can be a compile time constant and - * does not affect ABI or API */ +/* This is the max number of channels, changing this will change the + * size of some helper structures. This value should be at least 64 */ #ifndef SPA_AUDIO_MAX_CHANNELS -#define SPA_AUDIO_MAX_CHANNELS 128u +#define SPA_AUDIO_MAX_CHANNELS 64u #endif enum spa_audio_format { @@ -279,16 +275,18 @@ enum spa_audio_volume_ramp_scale { #define SPA_AUDIO_FLAG_NONE (0) /*< no valid flag */ #define SPA_AUDIO_FLAG_UNPOSITIONED (1 << 0) /*< the position array explicitly * contains unpositioned channels. */ -/** Audio information description */ +/** Audio information description. You can assume when you receive this structure + * that there is enought padding to accomodate all channel positions in case the + * channel count is more than SPA_AUDIO_MAX_CHANNELS. */ struct spa_audio_info_raw { enum spa_audio_format format; /*< format, one of enum spa_audio_format */ uint32_t flags; /*< extra flags */ uint32_t rate; /*< sample rate */ - uint32_t channels; /*< number of channels. This can be more than SPA_AUDIO_MAX_POSITION + uint32_t channels; /*< number of channels. This can be more than SPA_AUDIO_MAX_CHANNELS * and you may assume there is enough padding for the extra * channel positions. */ - uint32_t position[SPA_AUDIO_MAX_POSITION]; /*< channel position from enum spa_audio_channel */ - /* more channels can be added here */ + uint32_t position[SPA_AUDIO_MAX_CHANNELS]; /*< channel position from enum spa_audio_channel */ + /* padding follows here when channels > SPA_AUDIO_MAX_CHANNELS */ }; #define SPA_AUDIO_INFO_RAW_INIT(...) ((struct spa_audio_info_raw) { __VA_ARGS__ }) diff --git a/spa/lib/lib.c b/spa/lib/lib.c index 165fc81ba..30aa91194 100644 --- a/spa/lib/lib.c +++ b/spa/lib/lib.c @@ -1,4 +1,6 @@ +#undef SPA_AUDIO_MAX_CHANNELS + #define SPA_API_IMPL SPA_EXPORT #include #include @@ -165,9 +167,3 @@ #include #include #include - - - - - -