spa: make sure unpositioned raw audio has unknown channels

Otherwise we might end up with partial channels when code doesn't
check the unpositioned flag.  It's better to set everything to unknown
when there is a mismatch between channel count and layout.
This commit is contained in:
Wim Taymans 2025-11-27 11:45:21 +01:00
parent 172a2af982
commit 94c05e9e2d
2 changed files with 10 additions and 3 deletions

View file

@ -33,6 +33,8 @@ spa_format_audio_dsd_parse(const struct spa_pod *format, struct spa_audio_info_d
{
struct spa_pod *position = NULL;
int res;
uint32_t max_position = SPA_N_ELEMENTS(info->position);
info->flags = 0;
res = spa_pod_parse_object(format,
SPA_TYPE_OBJECT_Format, NULL,
@ -41,10 +43,13 @@ spa_format_audio_dsd_parse(const struct spa_pod *format, struct spa_audio_info_d
SPA_FORMAT_AUDIO_rate, SPA_POD_OPT_Int(&info->rate),
SPA_FORMAT_AUDIO_channels, SPA_POD_OPT_Int(&info->channels),
SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position));
if (info->channels > max_position)
return -ECHRNG;
if (position == NULL ||
!spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_N_ELEMENTS(info->position)))
spa_pod_copy_array(position, SPA_TYPE_Id, info->position, max_position) != info->channels) {
SPA_FLAG_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED);
spa_memzero(info->position, max_position * sizeof(info->position[0]));
}
return res;
}

View file

@ -48,8 +48,10 @@ spa_format_audio_raw_ext_parse(const struct spa_pod *format, struct spa_audio_in
if (info->channels > max_position)
return -ECHRNG;
if (position == NULL ||
spa_pod_copy_array(position, SPA_TYPE_Id, info->position, max_position) != info->channels)
spa_pod_copy_array(position, SPA_TYPE_Id, info->position, max_position) != info->channels) {
SPA_FLAG_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED);
spa_memzero(info->position, max_position * sizeof(info->position[0]));
}
return res;
}