mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
pod: add helper function to copy array values
This commit is contained in:
parent
b71f2dd716
commit
a1ec7f5fa7
2 changed files with 21 additions and 7 deletions
|
|
@ -47,13 +47,8 @@ spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_r
|
|||
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(&info->rate),
|
||||
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(&info->channels),
|
||||
SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position));
|
||||
if (position && spa_pod_is_array(position) &&
|
||||
SPA_POD_ARRAY_VALUE_TYPE(position) == SPA_TYPE_Id) {
|
||||
uint32_t *values = (uint32_t*)SPA_POD_ARRAY_VALUES(position);
|
||||
uint32_t n_values = SPA_MIN(SPA_POD_ARRAY_N_VALUES(position), SPA_AUDIO_MAX_CHANNELS);
|
||||
memcpy(info->position, values, n_values * sizeof(uint32_t));
|
||||
}
|
||||
else
|
||||
if (position == NULL ||
|
||||
!spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_AUDIO_MAX_CHANNELS))
|
||||
SPA_FLAG_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED);
|
||||
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -317,6 +317,25 @@ static inline int spa_pod_is_array(const struct spa_pod *pod)
|
|||
SPA_POD_BODY_SIZE(pod) >= sizeof(struct spa_pod_array_body));
|
||||
}
|
||||
|
||||
static inline void *spa_pod_get_array(const struct spa_pod *pod, uint32_t *n_values)
|
||||
{
|
||||
spa_return_val_if_fail(spa_pod_is_array(pod), NULL);
|
||||
*n_values = SPA_POD_ARRAY_N_VALUES(pod);
|
||||
return SPA_POD_ARRAY_VALUES(pod);
|
||||
}
|
||||
|
||||
static inline uint32_t spa_pod_copy_array(const struct spa_pod *pod, uint32_t type,
|
||||
void *values, uint32_t max_values)
|
||||
{
|
||||
uint32_t n_values;
|
||||
void *v = spa_pod_get_array(pod, &n_values);
|
||||
if (v == NULL || max_values == 0 || SPA_POD_ARRAY_VALUE_TYPE(pod) != type)
|
||||
return 0;
|
||||
n_values = SPA_MIN(n_values, max_values);
|
||||
memcpy(values, v, SPA_POD_ARRAY_VALUE_SIZE(pod) * n_values);
|
||||
return n_values;
|
||||
}
|
||||
|
||||
static inline int spa_pod_is_choice(const struct spa_pod *pod)
|
||||
{
|
||||
return (SPA_POD_TYPE(pod) == SPA_TYPE_Choice &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue