mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
pod: remove checks from spa_pod_body_get_*()
The pattern is _is_foo() and then _get_foo(). This allows us to reuse some of the get code in the parser without doing checks twice.
This commit is contained in:
parent
2c11f65701
commit
f7ae61cb1e
3 changed files with 174 additions and 150 deletions
|
|
@ -105,12 +105,9 @@ SPA_API_POD_BODY int spa_pod_is_bool(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Bool, sizeof(int32_t));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_bool(const struct spa_pod *pod, const void *body, bool *value)
|
||||
SPA_API_POD_BODY void spa_pod_body_get_bool(const struct spa_pod *pod, const void *body, bool *value)
|
||||
{
|
||||
if (!spa_pod_is_bool(pod))
|
||||
return -EINVAL;
|
||||
*value = !!*((int32_t*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_id(const struct spa_pod *pod)
|
||||
|
|
@ -118,12 +115,9 @@ SPA_API_POD_BODY int spa_pod_is_id(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Id, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_id(const struct spa_pod *pod, const void *body, uint32_t *value)
|
||||
SPA_API_POD_BODY void spa_pod_body_get_id(const struct spa_pod *pod, const void *body, uint32_t *value)
|
||||
{
|
||||
if (!spa_pod_is_id(pod))
|
||||
return -EINVAL;
|
||||
*value = *((uint32_t*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_int(const struct spa_pod *pod)
|
||||
|
|
@ -131,12 +125,9 @@ SPA_API_POD_BODY int spa_pod_is_int(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Int, sizeof(int32_t));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_int(const struct spa_pod *pod, const void *body, int32_t *value)
|
||||
SPA_API_POD_BODY void spa_pod_body_get_int(const struct spa_pod *pod, const void *body, int32_t *value)
|
||||
{
|
||||
if (!spa_pod_is_int(pod))
|
||||
return -EINVAL;
|
||||
*value = *((int32_t*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_long(const struct spa_pod *pod)
|
||||
|
|
@ -144,12 +135,9 @@ SPA_API_POD_BODY int spa_pod_is_long(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Long, sizeof(int64_t));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_long(const struct spa_pod *pod, const void *body, int64_t *value)
|
||||
SPA_API_POD_BODY void spa_pod_body_get_long(const struct spa_pod *pod, const void *body, int64_t *value)
|
||||
{
|
||||
if (!spa_pod_is_long(pod))
|
||||
return -EINVAL;
|
||||
*value = *((int64_t*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_float(const struct spa_pod *pod)
|
||||
|
|
@ -157,12 +145,9 @@ SPA_API_POD_BODY int spa_pod_is_float(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Float, sizeof(float));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_float(const struct spa_pod *pod, const void *body, float *value)
|
||||
SPA_API_POD_BODY void spa_pod_body_get_float(const struct spa_pod *pod, const void *body, float *value)
|
||||
{
|
||||
if (!spa_pod_is_float(pod))
|
||||
return -EINVAL;
|
||||
*value = *((float*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_double(const struct spa_pod *pod)
|
||||
|
|
@ -170,12 +155,9 @@ SPA_API_POD_BODY int spa_pod_is_double(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Double, sizeof(double));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_double(const struct spa_pod *pod, const void *body, double *value)
|
||||
SPA_API_POD_BODY void spa_pod_body_get_double(const struct spa_pod *pod, const void *body, double *value)
|
||||
{
|
||||
if (!spa_pod_is_double(pod))
|
||||
return -EINVAL;
|
||||
*value = *((double*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_string(const struct spa_pod *pod)
|
||||
|
|
@ -183,24 +165,21 @@ SPA_API_POD_BODY int spa_pod_is_string(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_String, 1);
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_string(const struct spa_pod *pod,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_string(const struct spa_pod *pod,
|
||||
const void *body, const char **value)
|
||||
{
|
||||
const char *s;
|
||||
if (!spa_pod_is_string(pod))
|
||||
return -EINVAL;
|
||||
s = (const char *)body;
|
||||
const char *s = (const char *)body;
|
||||
if (s[pod->size-1] != '\0')
|
||||
return -EINVAL;
|
||||
s = NULL;
|
||||
*value = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_copy_string(const struct spa_pod *pod, const void *body,
|
||||
size_t maxlen, char *dest)
|
||||
char *dest, size_t maxlen)
|
||||
{
|
||||
const char *s;
|
||||
if (spa_pod_body_get_string(pod, body, &s) < 0 || maxlen < 1)
|
||||
spa_pod_body_get_string(pod, body, &s);
|
||||
if (s == NULL || maxlen < 1)
|
||||
return -EINVAL;
|
||||
strncpy(dest, s, maxlen-1);
|
||||
dest[maxlen-1]= '\0';
|
||||
|
|
@ -212,14 +191,11 @@ SPA_API_POD_BODY int spa_pod_is_bytes(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK_TYPE(pod, SPA_TYPE_Bytes);
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_bytes(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_bytes(const struct spa_pod *pod, const void *body,
|
||||
const void **value, uint32_t *len)
|
||||
{
|
||||
if (!spa_pod_is_bytes(pod))
|
||||
return -EINVAL;
|
||||
*value = (const void *)body;
|
||||
*len = pod->size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_pointer(const struct spa_pod *pod)
|
||||
|
|
@ -227,14 +203,11 @@ SPA_API_POD_BODY int spa_pod_is_pointer(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Pointer, sizeof(struct spa_pod_pointer_body));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_pointer(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_pointer(const struct spa_pod *pod, const void *body,
|
||||
uint32_t *type, const void **value)
|
||||
{
|
||||
if (!spa_pod_is_pointer(pod))
|
||||
return -EINVAL;
|
||||
*type = ((struct spa_pod_pointer_body*)body)->type;
|
||||
*value = ((struct spa_pod_pointer_body*)body)->value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_fd(const struct spa_pod *pod)
|
||||
|
|
@ -242,13 +215,10 @@ SPA_API_POD_BODY int spa_pod_is_fd(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Fd, sizeof(int64_t));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_fd(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_fd(const struct spa_pod *pod, const void *body,
|
||||
int64_t *value)
|
||||
{
|
||||
if (!spa_pod_is_fd(pod))
|
||||
return -EINVAL;
|
||||
*value = *((int64_t*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_rectangle(const struct spa_pod *pod)
|
||||
|
|
@ -256,46 +226,42 @@ SPA_API_POD_BODY int spa_pod_is_rectangle(const struct spa_pod *pod)
|
|||
return SPA_POD_CHECK(pod, SPA_TYPE_Rectangle, sizeof(struct spa_rectangle));
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_body_get_rectangle(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_rectangle(const struct spa_pod *pod, const void *body,
|
||||
struct spa_rectangle *value)
|
||||
{
|
||||
if (!spa_pod_is_rectangle(pod))
|
||||
return -EINVAL;
|
||||
*value = *((struct spa_rectangle*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_fraction(const struct spa_pod *pod)
|
||||
{
|
||||
return SPA_POD_CHECK(pod, SPA_TYPE_Fraction, sizeof(struct spa_fraction));
|
||||
}
|
||||
SPA_API_POD_BODY int spa_pod_body_get_fraction(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_fraction(const struct spa_pod *pod, const void *body,
|
||||
struct spa_fraction *value)
|
||||
{
|
||||
if (!spa_pod_is_fraction(pod))
|
||||
return -EINVAL;
|
||||
*value = *((struct spa_fraction*)body);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_bitmap(const struct spa_pod *pod)
|
||||
{
|
||||
return SPA_POD_CHECK(pod, SPA_TYPE_Bitmap, sizeof(uint8_t));
|
||||
}
|
||||
SPA_API_POD_BODY void spa_pod_body_get_bitmap(const struct spa_pod *pod, const void *body,
|
||||
const uint8_t **value)
|
||||
{
|
||||
*value = (const uint8_t *)body;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_array(const struct spa_pod *pod)
|
||||
{
|
||||
return SPA_POD_CHECK(pod, SPA_TYPE_Array, sizeof(struct spa_pod_array_body));
|
||||
}
|
||||
SPA_API_POD_BODY int spa_pod_body_get_array(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_array(const struct spa_pod *pod, const void *body,
|
||||
struct spa_pod_array *arr, const void **arr_body)
|
||||
{
|
||||
if (!spa_pod_is_array(pod))
|
||||
return -EINVAL;
|
||||
arr->pod = *pod;
|
||||
memcpy(&arr->body, body, sizeof(struct spa_pod_array_body));
|
||||
*arr_body = SPA_PTROFF(body, sizeof(struct spa_pod_array_body), void);
|
||||
return 0;
|
||||
}
|
||||
SPA_API_POD_BODY const void *spa_pod_array_body_get_values(const struct spa_pod_array *arr,
|
||||
const void *body, uint32_t *n_values, uint32_t *val_size, uint32_t *val_type)
|
||||
|
|
@ -311,8 +277,7 @@ SPA_API_POD_BODY const void *spa_pod_body_get_array_values(const struct spa_pod
|
|||
const void *body, uint32_t *n_values, uint32_t *val_size, uint32_t *val_type)
|
||||
{
|
||||
struct spa_pod_array arr;
|
||||
if (spa_pod_body_get_array(pod, body, &arr, &body) < 0)
|
||||
return NULL;
|
||||
spa_pod_body_get_array(pod, body, &arr, &body);
|
||||
return spa_pod_array_body_get_values(&arr, body, n_values, val_size, val_type);
|
||||
}
|
||||
|
||||
|
|
@ -320,15 +285,12 @@ SPA_API_POD_BODY int spa_pod_is_choice(const struct spa_pod *pod)
|
|||
{
|
||||
return SPA_POD_CHECK(pod, SPA_TYPE_Choice, sizeof(struct spa_pod_choice_body));
|
||||
}
|
||||
SPA_API_POD_BODY int spa_pod_body_get_choice(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_choice(const struct spa_pod *pod, const void *body,
|
||||
struct spa_pod_choice *choice, const void **choice_body)
|
||||
{
|
||||
if (!spa_pod_is_choice(pod))
|
||||
return -EINVAL;
|
||||
choice->pod = *pod;
|
||||
memcpy(&choice->body, body, sizeof(struct spa_pod_choice_body));
|
||||
*choice_body = SPA_PTROFF(body, sizeof(struct spa_pod_choice_body), void);
|
||||
return 0;
|
||||
}
|
||||
SPA_API_POD_BODY const void *spa_pod_choice_body_get_values(const struct spa_pod_choice *pod,
|
||||
const void *body, uint32_t *n_values, uint32_t *choice,
|
||||
|
|
@ -353,30 +315,24 @@ SPA_API_POD_BODY int spa_pod_is_object(const struct spa_pod *pod)
|
|||
{
|
||||
return SPA_POD_CHECK(pod, SPA_TYPE_Object, sizeof(struct spa_pod_object_body));
|
||||
}
|
||||
SPA_API_POD_BODY int spa_pod_body_get_object(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_object(const struct spa_pod *pod, const void *body,
|
||||
struct spa_pod_object *object, const void **object_body)
|
||||
{
|
||||
if (!spa_pod_is_object(pod))
|
||||
return -EINVAL;
|
||||
object->pod = *pod;
|
||||
memcpy(&object->body, body, sizeof(struct spa_pod_object_body));
|
||||
*object_body = SPA_PTROFF(body, sizeof(struct spa_pod_object_body), void);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_BODY int spa_pod_is_sequence(const struct spa_pod *pod)
|
||||
{
|
||||
return SPA_POD_CHECK(pod, SPA_TYPE_Sequence, sizeof(struct spa_pod_sequence_body));
|
||||
}
|
||||
SPA_API_POD_BODY int spa_pod_body_get_sequence(const struct spa_pod *pod, const void *body,
|
||||
SPA_API_POD_BODY void spa_pod_body_get_sequence(const struct spa_pod *pod, const void *body,
|
||||
struct spa_pod_sequence *seq, const void **seq_body)
|
||||
{
|
||||
if (!spa_pod_is_sequence(pod))
|
||||
return -EINVAL;
|
||||
seq->pod = *pod;
|
||||
memcpy(&seq->body, body, sizeof(struct spa_pod_sequence_body));
|
||||
*seq_body = SPA_PTROFF(body, sizeof(struct spa_pod_sequence_body), void);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -130,72 +130,112 @@ SPA_API_POD_ITER void *spa_pod_from_data(void *data, size_t maxsize, off_t offse
|
|||
|
||||
SPA_API_POD_ITER int spa_pod_get_bool(const struct spa_pod *pod, bool *value)
|
||||
{
|
||||
return spa_pod_body_get_bool(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_bool(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_bool(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_id(const struct spa_pod *pod, uint32_t *value)
|
||||
{
|
||||
return spa_pod_body_get_id(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_id(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_id(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_int(const struct spa_pod *pod, int32_t *value)
|
||||
{
|
||||
return spa_pod_body_get_int(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_int(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_int(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_long(const struct spa_pod *pod, int64_t *value)
|
||||
{
|
||||
return spa_pod_body_get_long(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_long(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_long(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_float(const struct spa_pod *pod, float *value)
|
||||
{
|
||||
return spa_pod_body_get_float(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_float(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_float(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_double(const struct spa_pod *pod, double *value)
|
||||
{
|
||||
return spa_pod_body_get_double(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_double(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_double(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_string(const struct spa_pod *pod, const char **value)
|
||||
{
|
||||
return spa_pod_body_get_string(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_string(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_string(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return *value ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_copy_string(const struct spa_pod *pod, size_t maxlen, char *dest)
|
||||
{
|
||||
return spa_pod_body_copy_string(pod, SPA_POD_BODY_CONST(pod), maxlen, dest);
|
||||
if (!spa_pod_is_string(pod))
|
||||
return -EINVAL;
|
||||
return spa_pod_body_copy_string(pod, SPA_POD_BODY_CONST(pod), dest, maxlen);
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_bytes(const struct spa_pod *pod, const void **value, uint32_t *len)
|
||||
{
|
||||
return spa_pod_body_get_bytes(pod, SPA_POD_BODY_CONST(pod), value, len);
|
||||
if (!spa_pod_is_bytes(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_bytes(pod, SPA_POD_BODY_CONST(pod), value, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_pointer(const struct spa_pod *pod, uint32_t *type, const void **value)
|
||||
{
|
||||
return spa_pod_body_get_pointer(pod, SPA_POD_BODY_CONST(pod), type, value);
|
||||
if (!spa_pod_is_pointer(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_pointer(pod, SPA_POD_BODY_CONST(pod), type, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_fd(const struct spa_pod *pod, int64_t *value)
|
||||
{
|
||||
return spa_pod_body_get_fd(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_fd(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_fd(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_rectangle(const struct spa_pod *pod, struct spa_rectangle *value)
|
||||
{
|
||||
return spa_pod_body_get_rectangle(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_rectangle(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_rectangle(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER int spa_pod_get_fraction(const struct spa_pod *pod, struct spa_fraction *value)
|
||||
{
|
||||
return spa_pod_body_get_fraction(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
if (!spa_pod_is_fraction(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_fraction(pod, SPA_POD_BODY_CONST(pod), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPA_API_POD_ITER void *spa_pod_get_array_full(const struct spa_pod *pod, uint32_t *n_values,
|
||||
uint32_t *val_size, uint32_t *val_type)
|
||||
{
|
||||
if (!spa_pod_is_array(pod))
|
||||
return NULL;
|
||||
return (void*)spa_pod_body_get_array_values(pod, SPA_POD_BODY(pod), n_values, val_size, val_type);
|
||||
}
|
||||
SPA_API_POD_ITER void *spa_pod_get_array(const struct spa_pod *pod, uint32_t *n_values)
|
||||
|
|
|
|||
|
|
@ -201,8 +201,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_bool(struct spa_pod_parser *parser, bo
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_bool(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_bool(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_bool(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -213,8 +215,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_id(struct spa_pod_parser *parser, uint
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_id(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_id(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_id(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -225,8 +229,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_int(struct spa_pod_parser *parser, int
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_int(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_int(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_int(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -237,8 +243,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_long(struct spa_pod_parser *parser, in
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_long(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_long(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_long(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -249,8 +257,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_float(struct spa_pod_parser *parser, f
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_float(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_float(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_float(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -261,8 +271,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_double(struct spa_pod_parser *parser,
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_double(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_double(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_double(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -273,8 +285,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_string(struct spa_pod_parser *parser,
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_string(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_string(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_string(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -285,8 +299,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_bytes(struct spa_pod_parser *parser, c
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_bytes(&pod, body, value, len)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_bytes(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_bytes(&pod, body, value, len);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -297,8 +313,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_pointer(struct spa_pod_parser *parser,
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_pointer(&pod, body, type, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_pointer(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_pointer(&pod, body, type, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -309,8 +327,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_fd(struct spa_pod_parser *parser, int6
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_fd(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_fd(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_fd(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -321,8 +341,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_rectangle(struct spa_pod_parser *parse
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_rectangle(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_rectangle(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_rectangle(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -333,8 +355,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_fraction(struct spa_pod_parser *parser
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_fraction(&pod, body, value)) >= 0)
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
if (!spa_pod_is_fraction(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_fraction(&pod, body, value);
|
||||
spa_pod_parser_advance(parser, &pod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -394,12 +418,10 @@ SPA_API_POD_PARSER int spa_pod_parser_init_object_body(struct spa_pod_parser *pa
|
|||
struct spa_pod_frame *frame, const struct spa_pod *pod, const void *body,
|
||||
struct spa_pod_object *object, const void **object_body)
|
||||
{
|
||||
int res;
|
||||
if (!spa_pod_is_object(pod))
|
||||
return -EINVAL;
|
||||
spa_pod_parser_init_pod_body(parser, pod, body);
|
||||
if ((res = spa_pod_body_get_object(pod, body, object, object_body)) < 0)
|
||||
return res;
|
||||
spa_pod_body_get_object(pod, body, object, object_body);
|
||||
spa_pod_parser_push(parser, frame, pod, parser->state.offset);
|
||||
parser->state.offset += sizeof(struct spa_pod_object);
|
||||
return 0;
|
||||
|
|
@ -413,8 +435,9 @@ SPA_API_POD_PARSER int spa_pod_parser_push_object_body(struct spa_pod_parser *pa
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_object(&pod, body, object, object_body)) < 0)
|
||||
return res;
|
||||
if (!spa_pod_is_object(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_object(&pod, body, object, object_body);
|
||||
spa_pod_parser_push(parser, frame, &pod, parser->state.offset);
|
||||
parser->state.offset += sizeof(struct spa_pod_object);
|
||||
return 0;
|
||||
|
|
@ -454,8 +477,9 @@ SPA_API_POD_PARSER int spa_pod_parser_push_sequence_body(struct spa_pod_parser *
|
|||
const void *body;
|
||||
if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
|
||||
return res;
|
||||
if ((res = spa_pod_body_get_sequence(&pod, body, seq, seq_body)) < 0)
|
||||
return res;
|
||||
if (!spa_pod_is_sequence(&pod))
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_sequence(&pod, body, seq, seq_body);
|
||||
spa_pod_parser_push(parser, frame, &pod, parser->state.offset);
|
||||
parser->state.offset += sizeof(struct spa_pod_sequence);
|
||||
return 0;
|
||||
|
|
@ -508,8 +532,7 @@ SPA_API_POD_PARSER bool spa_pod_parser_body_can_collect(const struct spa_pod *po
|
|||
return false;
|
||||
if (type == 'V')
|
||||
return true;
|
||||
if (spa_pod_body_get_choice(pod, body, &choice, &body) < 0)
|
||||
return false;
|
||||
spa_pod_body_get_choice(pod, body, &choice, &body);
|
||||
if (choice.body.type != SPA_CHOICE_None)
|
||||
return false;
|
||||
pod = &choice.body.child;
|
||||
|
|
@ -566,72 +589,78 @@ SPA_API_POD_PARSER bool spa_pod_parser_can_collect(const struct spa_pod *pod, ch
|
|||
do { \
|
||||
switch (_type) { \
|
||||
case 'b': \
|
||||
*va_arg(args, bool*) = !!*((int32_t*)(body)); \
|
||||
spa_pod_body_get_bool(pod, body, va_arg(args, bool*)); \
|
||||
break; \
|
||||
case 'I': \
|
||||
spa_pod_body_get_id(pod, body, va_arg(args, uint32_t*)); \
|
||||
break; \
|
||||
case 'i': \
|
||||
*va_arg(args, int32_t*) = *((int32_t*)(body)); \
|
||||
spa_pod_body_get_int(pod, body, va_arg(args, int32_t*)); \
|
||||
break; \
|
||||
case 'l': \
|
||||
*va_arg(args, int64_t*) = *((int64_t*)(body)); \
|
||||
spa_pod_body_get_long(pod, body, va_arg(args, int64_t*)); \
|
||||
break; \
|
||||
case 'f': \
|
||||
*va_arg(args, float*) = *((float*)(body)); \
|
||||
spa_pod_body_get_float(pod, body, va_arg(args, float*)); \
|
||||
break; \
|
||||
case 'd': \
|
||||
*va_arg(args, double*) = *((double*)(body)); \
|
||||
spa_pod_body_get_double(pod, body, va_arg(args, double*)); \
|
||||
break; \
|
||||
case 's': \
|
||||
*va_arg(args, char**) = ((pod)->type == SPA_TYPE_None) ? \
|
||||
NULL : (char *)(body); \
|
||||
{ \
|
||||
const char **dest = va_arg(args, const char**); \
|
||||
if ((pod)->type == SPA_TYPE_None) \
|
||||
*dest = NULL; \
|
||||
else \
|
||||
spa_pod_body_get_string(pod, body, dest); \
|
||||
break; \
|
||||
} \
|
||||
case 'S': \
|
||||
{ \
|
||||
char *dest = va_arg(args, char*); \
|
||||
uint32_t maxlen = va_arg(args, uint32_t); \
|
||||
maxlen = SPA_MIN(maxlen, (pod)->size); \
|
||||
strncpy(dest, (char *)(body), maxlen-1); \
|
||||
dest[maxlen-1] = '\0'; \
|
||||
spa_pod_body_copy_string(pod, body, dest, maxlen); \
|
||||
break; \
|
||||
} \
|
||||
case 'y': \
|
||||
*(va_arg(args, void **)) = (void*)(body); \
|
||||
*(va_arg(args, uint32_t *)) = (pod)->size; \
|
||||
{ \
|
||||
const void **value = va_arg(args, const void**); \
|
||||
uint32_t *len = va_arg(args, uint32_t*); \
|
||||
spa_pod_body_get_bytes(pod, body, value, len); \
|
||||
break; \
|
||||
} \
|
||||
case 'R': \
|
||||
*va_arg(args, struct spa_rectangle*) = \
|
||||
*((struct spa_rectangle*)(body)); \
|
||||
spa_pod_body_get_rectangle(pod, body, \
|
||||
va_arg(args, struct spa_rectangle*)); \
|
||||
break; \
|
||||
case 'F': \
|
||||
*va_arg(args, struct spa_fraction*) = \
|
||||
*((struct spa_fraction*)(body)); \
|
||||
spa_pod_body_get_fraction(pod, body, \
|
||||
va_arg(args, struct spa_fraction*)); \
|
||||
break; \
|
||||
case 'B': \
|
||||
*va_arg(args, uint32_t **) = (uint32_t*)(body); \
|
||||
spa_pod_body_get_bitmap(pod, body, va_arg(args, const uint8_t**)); \
|
||||
break; \
|
||||
case 'a': \
|
||||
{ \
|
||||
struct spa_pod_array_body *b = \
|
||||
(struct spa_pod_array_body*)(body); \
|
||||
uint32_t child_size = b->child.size; \
|
||||
*va_arg(args, uint32_t*) = child_size; \
|
||||
*va_arg(args, uint32_t*) = b->child.type; \
|
||||
*va_arg(args, uint32_t*) = child_size ? \
|
||||
((pod)->size - sizeof(struct spa_pod_array_body))/child_size : 0; \
|
||||
*va_arg(args, void**) = SPA_PTROFF(b, \
|
||||
sizeof(struct spa_pod_array_body), void); \
|
||||
struct spa_pod_array arr; \
|
||||
uint32_t *val_size = va_arg(args, uint32_t*); \
|
||||
uint32_t *val_type = va_arg(args, uint32_t*); \
|
||||
uint32_t *n_values = va_arg(args, uint32_t*); \
|
||||
const void **arr_body = va_arg(args, const void**); \
|
||||
spa_pod_body_get_array(pod, body, &arr, arr_body); \
|
||||
spa_pod_array_body_get_values(&arr, *arr_body, \
|
||||
n_values, val_size, val_type); \
|
||||
break; \
|
||||
} \
|
||||
case 'p': \
|
||||
{ \
|
||||
struct spa_pod_pointer_body *b = \
|
||||
(struct spa_pod_pointer_body *)(body); \
|
||||
*(va_arg(args, uint32_t *)) = b->type; \
|
||||
*(va_arg(args, const void **)) = b->value; \
|
||||
uint32_t *type = va_arg(args, uint32_t*); \
|
||||
const void **value = va_arg(args, const void**); \
|
||||
spa_pod_body_get_pointer(pod, body, type, value); \
|
||||
break; \
|
||||
} \
|
||||
case 'h': \
|
||||
*va_arg(args, int64_t*) = *((int64_t*)(body)); \
|
||||
spa_pod_body_get_fd(pod, body, va_arg(args, int64_t*)); \
|
||||
break; \
|
||||
case 'P': \
|
||||
case 'T': \
|
||||
|
|
@ -736,8 +765,7 @@ SPA_API_POD_PARSER int spa_pod_parser_getv(struct spa_pod_parser *parser, va_lis
|
|||
struct spa_pod_choice choice;
|
||||
|
||||
if (pod.type == SPA_TYPE_Choice && *format != 'V') {
|
||||
if (spa_pod_body_get_choice(&pod, body, &choice, &body) < 0)
|
||||
return -EINVAL;
|
||||
spa_pod_body_get_choice(&pod, body, &choice, &body);
|
||||
pod = choice.body.child;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue