mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
parser: add some utils to parse values
This commit is contained in:
parent
0303b7d1c5
commit
9d44d0b135
2 changed files with 41 additions and 2 deletions
|
|
@ -320,6 +320,45 @@ static inline int spa_pod_parser_get(struct spa_pod_parser *parser,
|
|||
spa_pod_parser_get(&__p, "{", ##__VA_ARGS__, NULL); \
|
||||
})
|
||||
|
||||
static inline int spa_pod_is_bool(struct spa_pod *pod)
|
||||
{
|
||||
return (SPA_POD_TYPE(pod) == SPA_TYPE_Bool && SPA_POD_BODY_SIZE(pod) >= sizeof(int32_t));
|
||||
}
|
||||
|
||||
static inline int spa_pod_get_bool(struct spa_pod *pod, bool *value)
|
||||
{
|
||||
if (!spa_pod_is_bool(pod))
|
||||
return -EINVAL;
|
||||
*value = SPA_POD_VALUE(struct spa_pod_bool, pod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int spa_pod_is_float(struct spa_pod *pod)
|
||||
{
|
||||
return (SPA_POD_TYPE(pod) == SPA_TYPE_Float && SPA_POD_BODY_SIZE(pod) >= sizeof(float));
|
||||
}
|
||||
|
||||
static inline int spa_pod_get_float(struct spa_pod *pod, float *value)
|
||||
{
|
||||
if (!spa_pod_is_float(pod))
|
||||
return -EINVAL;
|
||||
*value = SPA_POD_VALUE(struct spa_pod_float, pod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int spa_pod_is_double(struct spa_pod *pod)
|
||||
{
|
||||
return (SPA_POD_TYPE(pod) == SPA_TYPE_Double && SPA_POD_BODY_SIZE(pod) >= sizeof(double));
|
||||
}
|
||||
|
||||
static inline int spa_pod_get_double(struct spa_pod *pod, double *value)
|
||||
{
|
||||
if (!spa_pod_is_double(pod))
|
||||
return -EINVAL;
|
||||
*value = SPA_POD_VALUE(struct spa_pod_double, pod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -517,10 +517,10 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
|
|||
SPA_POD_OBJECT_FOREACH(obj, prop) {
|
||||
switch (prop->key) {
|
||||
case SPA_PROP_volume:
|
||||
p->volume = SPA_POD_VALUE(struct spa_pod_float, &prop->value);
|
||||
spa_pod_get_float(&prop->value, &p->volume);
|
||||
break;
|
||||
case SPA_PROP_mute:
|
||||
p->mute = SPA_POD_VALUE(struct spa_pod_bool, &prop->value);
|
||||
spa_pod_get_bool(&prop->value, &p->mute);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue