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.
This commit is contained in:
Wim Taymans 2025-10-20 15:28:51 +02:00
parent c94aff8cae
commit f453b1545d
14 changed files with 22 additions and 18 deletions

View file

@ -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))

View file

@ -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))

View file

@ -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))

View file

@ -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))

View file

@ -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;

View file

@ -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))

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);