From f453b1545dc229f992a8da9dbb31a2fab634c6c1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Oct 2025 15:28:51 +0200 Subject: [PATCH] audio: don't use SPA_AUDIO_MAX_CHANNELS in some places When we know the max size of the array, just use this instead of the SPA_AUDIO_MAX_CHANNELS constant. --- spa/plugins/bluez5/a2dp-codec-aac.c | 2 +- spa/plugins/bluez5/a2dp-codec-aptx.c | 2 +- spa/plugins/bluez5/a2dp-codec-faststream.c | 2 +- spa/plugins/bluez5/a2dp-codec-lc3plus.c | 2 +- spa/plugins/bluez5/a2dp-codec-ldac.c | 2 +- spa/plugins/bluez5/a2dp-codec-opus-g.c | 2 +- spa/plugins/bluez5/a2dp-codec-sbc.c | 2 +- spa/plugins/bluez5/bap-codec-lc3.c | 11 ++++++----- spa/plugins/bluez5/hfp-codec-cvsd.c | 2 +- spa/plugins/bluez5/hfp-codec-lc3-a127.c | 2 +- spa/plugins/bluez5/hfp-codec-lc3-swb.c | 2 +- spa/plugins/bluez5/hfp-codec-msbc.c | 2 +- src/gst/gstpipewireformat.c | 2 +- src/modules/module-rtp/opus.c | 5 ++++- 14 files changed, 22 insertions(+), 18 deletions(-) diff --git a/spa/plugins/bluez5/a2dp-codec-aac.c b/spa/plugins/bluez5/a2dp-codec-aac.c index 505066c3e..6d4db7fc4 100644 --- a/spa/plugins/bluez5/a2dp-codec-aac.c +++ b/spa/plugins/bluez5/a2dp-codec-aac.c @@ -200,7 +200,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, a2dp_aac_t conf; struct spa_pod_frame f[2]; struct spa_pod_choice *choice; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; uint32_t i = 0; if (caps_size < sizeof(conf)) diff --git a/spa/plugins/bluez5/a2dp-codec-aptx.c b/spa/plugins/bluez5/a2dp-codec-aptx.c index 7ebdc99d8..75ceb229f 100644 --- a/spa/plugins/bluez5/a2dp-codec-aptx.c +++ b/spa/plugins/bluez5/a2dp-codec-aptx.c @@ -205,7 +205,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, a2dp_aptx_t conf; struct spa_pod_frame f[2]; struct spa_pod_choice *choice; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; uint32_t i = 0; if (caps_size < sizeof(conf)) diff --git a/spa/plugins/bluez5/a2dp-codec-faststream.c b/spa/plugins/bluez5/a2dp-codec-faststream.c index 5b78fb38e..edc833292 100644 --- a/spa/plugins/bluez5/a2dp-codec-faststream.c +++ b/spa/plugins/bluez5/a2dp-codec-faststream.c @@ -114,7 +114,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, a2dp_faststream_t conf; struct spa_pod_frame f[2]; struct spa_pod_choice *choice; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; uint32_t i = 0; if (caps_size < sizeof(conf)) diff --git a/spa/plugins/bluez5/a2dp-codec-lc3plus.c b/spa/plugins/bluez5/a2dp-codec-lc3plus.c index c5a191e29..ee25fef0c 100644 --- a/spa/plugins/bluez5/a2dp-codec-lc3plus.c +++ b/spa/plugins/bluez5/a2dp-codec-lc3plus.c @@ -175,7 +175,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, a2dp_lc3plus_hr_t conf; struct spa_pod_frame f[2]; struct spa_pod_choice *choice; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; uint32_t i = 0; if (caps_size < sizeof(conf)) diff --git a/spa/plugins/bluez5/a2dp-codec-ldac.c b/spa/plugins/bluez5/a2dp-codec-ldac.c index cf1526faf..11185800e 100644 --- a/spa/plugins/bluez5/a2dp-codec-ldac.c +++ b/spa/plugins/bluez5/a2dp-codec-ldac.c @@ -158,7 +158,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, struct spa_pod_frame f[2]; struct spa_pod_choice *choice; uint32_t i = 0; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; if (caps_size < sizeof(conf)) return -EINVAL; diff --git a/spa/plugins/bluez5/a2dp-codec-opus-g.c b/spa/plugins/bluez5/a2dp-codec-opus-g.c index 2fe34bf5e..130dea433 100644 --- a/spa/plugins/bluez5/a2dp-codec-opus-g.c +++ b/spa/plugins/bluez5/a2dp-codec-opus-g.c @@ -164,7 +164,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, { a2dp_opus_g_t conf; struct spa_pod_frame f[1]; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; int channels; if (caps_size < sizeof(conf)) diff --git a/spa/plugins/bluez5/a2dp-codec-sbc.c b/spa/plugins/bluez5/a2dp-codec-sbc.c index f2bc3e7ef..a91109e52 100644 --- a/spa/plugins/bluez5/a2dp-codec-sbc.c +++ b/spa/plugins/bluez5/a2dp-codec-sbc.c @@ -346,7 +346,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, struct spa_pod_frame f[2]; struct spa_pod_choice *choice; uint32_t i = 0; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[2]; if (caps_size < sizeof(conf)) return -EINVAL; diff --git a/spa/plugins/bluez5/bap-codec-lc3.c b/spa/plugins/bluez5/bap-codec-lc3.c index 818f4ee36..10d9eecc8 100644 --- a/spa/plugins/bluez5/bap-codec-lc3.c +++ b/spa/plugins/bluez5/bap-codec-lc3.c @@ -901,12 +901,12 @@ static int codec_caps_preference_cmp(const struct media_codec *codec, uint32_t f return conf_cmp(&conf1, res1, &conf2, res2); } -static uint8_t channels_to_positions(uint32_t channels, uint32_t *position) +static uint8_t channels_to_positions(uint32_t channels, uint32_t *position, uint32_t max_position) { uint32_t n_channels = get_channel_count(channels); uint8_t n_positions = 0; - spa_assert(n_channels <= SPA_AUDIO_MAX_CHANNELS); + spa_assert(n_channels <= max_position); if (channels == 0) { position[0] = SPA_AUDIO_CHANNEL_MONO; @@ -932,7 +932,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, bap_lc3_t conf; struct spa_pod_frame f[2]; struct spa_pod_choice *choice; - uint32_t position[SPA_AUDIO_MAX_CHANNELS]; + uint32_t position[LC3_MAX_CHANNELS]; uint32_t i = 0; uint8_t res; @@ -990,7 +990,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, if (i == 0) return -EINVAL; - res = channels_to_positions(conf.channels, position); + res = channels_to_positions(conf.channels, position, SPA_N_ELEMENTS(position)); if (res == 0) return -EINVAL; spa_pod_builder_add(b, @@ -1044,7 +1044,8 @@ static int codec_validate_config(const struct media_codec *codec, uint32_t flags return -EINVAL; } - res = channels_to_positions(conf.channels, info->info.raw.position); + res = channels_to_positions(conf.channels, info->info.raw.position, + SPA_N_ELEMENTS(info->info.raw.position)); if (res == 0) return -EINVAL; info->info.raw.channels = res; diff --git a/spa/plugins/bluez5/hfp-codec-cvsd.c b/spa/plugins/bluez5/hfp-codec-cvsd.c index 66b801ecc..19f908188 100644 --- a/spa/plugins/bluez5/hfp-codec-cvsd.c +++ b/spa/plugins/bluez5/hfp-codec-cvsd.c @@ -34,7 +34,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, struct spa_pod_builder *b, struct spa_pod **param) { struct spa_pod_frame f[1]; - const uint32_t position[SPA_AUDIO_MAX_CHANNELS] = { SPA_AUDIO_CHANNEL_MONO }; + const uint32_t position[1] = { SPA_AUDIO_CHANNEL_MONO }; const int channels = 1; spa_assert(caps == NULL && caps_size == 0); diff --git a/spa/plugins/bluez5/hfp-codec-lc3-a127.c b/spa/plugins/bluez5/hfp-codec-lc3-a127.c index 703e153a8..b10bba874 100644 --- a/spa/plugins/bluez5/hfp-codec-lc3-a127.c +++ b/spa/plugins/bluez5/hfp-codec-lc3-a127.c @@ -39,7 +39,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, struct spa_pod_builder *b, struct spa_pod **param) { struct spa_pod_frame f[1]; - const uint32_t position[SPA_AUDIO_MAX_CHANNELS] = { SPA_AUDIO_CHANNEL_MONO }; + const uint32_t position[1] = { SPA_AUDIO_CHANNEL_MONO }; const int channels = 1; spa_assert(caps == NULL && caps_size == 0); diff --git a/spa/plugins/bluez5/hfp-codec-lc3-swb.c b/spa/plugins/bluez5/hfp-codec-lc3-swb.c index 685806286..1cd679958 100644 --- a/spa/plugins/bluez5/hfp-codec-lc3-swb.c +++ b/spa/plugins/bluez5/hfp-codec-lc3-swb.c @@ -42,7 +42,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, struct spa_pod_builder *b, struct spa_pod **param) { struct spa_pod_frame f[1]; - const uint32_t position[SPA_AUDIO_MAX_CHANNELS] = { SPA_AUDIO_CHANNEL_MONO }; + const uint32_t position[1] = { SPA_AUDIO_CHANNEL_MONO }; const int channels = 1; spa_assert(caps == NULL && caps_size == 0); diff --git a/spa/plugins/bluez5/hfp-codec-msbc.c b/spa/plugins/bluez5/hfp-codec-msbc.c index d2aabe2b0..5175a68d7 100644 --- a/spa/plugins/bluez5/hfp-codec-msbc.c +++ b/spa/plugins/bluez5/hfp-codec-msbc.c @@ -49,7 +49,7 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, struct spa_pod_builder *b, struct spa_pod **param) { struct spa_pod_frame f[1]; - const uint32_t position[SPA_AUDIO_MAX_CHANNELS] = { SPA_AUDIO_CHANNEL_MONO }; + const uint32_t position[1] = { SPA_AUDIO_CHANNEL_MONO }; const int channels = 1; spa_assert(caps == NULL && caps_size == 0); diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c index 20b93065a..fa97d3e01 100644 --- a/src/gst/gstpipewireformat.c +++ b/src/gst/gstpipewireformat.c @@ -649,7 +649,7 @@ handle_video_fields (ConvertData *d) static void set_default_channels (struct spa_pod_builder *b, uint32_t channels) { - uint32_t position[SPA_AUDIO_MAX_CHANNELS] = {0}; + uint32_t position[8] = {0}; gboolean ok = TRUE; switch (channels) { diff --git a/src/modules/module-rtp/opus.c b/src/modules/module-rtp/opus.c index 6f27bd2bd..7eeda7f43 100644 --- a/src/modules/module-rtp/opus.c +++ b/src/modules/module-rtp/opus.c @@ -334,9 +334,12 @@ static void rtp_opus_deinit(struct impl *impl, enum spa_direction direction) static int rtp_opus_init(struct impl *impl, enum spa_direction direction) { int err; - unsigned char mapping[SPA_AUDIO_MAX_CHANNELS]; + unsigned char mapping[255]; uint32_t i; + if (impl->info.info.opus.channels > 255) + return -EINVAL; + if (impl->psamples >= 2880) impl->psamples = 2880; else if (impl->psamples >= 1920)