From f19b075306900fb3650aa821ff2120b7804151a2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 21 Oct 2025 16:08:24 +0200 Subject: [PATCH] spa: add SPA_AUDIO_MAX_POSITION Add a new SPA_AUDIO_MAX_POSITION constant with the maximum number of channel positions that can be kept in the various audio_info structures. Repurpose the SPA_AUDIO_MAX_CHANNELS as a suggestion for applications for the max allowed number of channels in the system. Make it possible to make this a compile time constant. --- 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 | 15 +++++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spa/include/spa/param/audio/dsd.h b/spa/include/spa/param/audio/dsd.h index 73f3d4e8b..733823780 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_CHANNELS]; /*< channel position from enum spa_audio_channel */ + uint32_t position[SPA_AUDIO_MAX_POSITION]; /*< 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 19e3a3c42..e5e59caf9 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_CHANNELS]; + uint32_t position[SPA_AUDIO_MAX_POSITION]; }; #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 50bd63181..edbb715d1 100644 --- a/spa/include/spa/param/audio/raw-json.h +++ b/spa/include/spa/param/audio/raw-json.h @@ -49,7 +49,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_CHANNELS, n_channels); + return spa_audio_parse_position_n(str, len, position, SPA_AUDIO_MAX_POSITION, 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 6defe5020..21cdb3c2d 100644 --- a/spa/include/spa/param/audio/raw.h +++ b/spa/include/spa/param/audio/raw.h @@ -18,8 +18,15 @@ extern "C" { * \{ */ -/* this is the max number of channels for position info */ +/* 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 */ +#ifndef SPA_AUDIO_MAX_CHANNELS #define SPA_AUDIO_MAX_CHANNELS 64u +#endif enum spa_audio_format { SPA_AUDIO_FORMAT_UNKNOWN, @@ -278,9 +285,9 @@ struct spa_audio_info_raw { uint32_t flags; /*< extra flags */ uint32_t rate; /*< sample rate */ uint32_t channels; /*< number of channels. This can be larger than - * SPA_AUDIO_MAX_CHANNELS, the position is taken - * (index % SPA_AUDIO_MAX_CHANNELS) */ - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; /*< channel position from enum spa_audio_channel */ + * SPA_AUDIO_MAX_POSITION, the position is taken + * (index % SPA_AUDIO_MAX_POSITION) */ + uint32_t position[SPA_AUDIO_MAX_POSITION]; /*< channel position from enum spa_audio_channel */ }; #define SPA_AUDIO_INFO_RAW_INIT(...) ((struct spa_audio_info_raw) { __VA_ARGS__ })