mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05: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));
 | 
						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);
 | 
						*value = !!*((int32_t*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_id(const struct spa_pod *pod)
 | 
					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));
 | 
						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);
 | 
						*value = *((uint32_t*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_int(const struct spa_pod *pod)
 | 
					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));
 | 
						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);
 | 
						*value = *((int32_t*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_long(const struct spa_pod *pod)
 | 
					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));
 | 
						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);
 | 
						*value = *((int64_t*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_float(const struct spa_pod *pod)
 | 
					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));
 | 
						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);
 | 
						*value = *((float*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_double(const struct spa_pod *pod)
 | 
					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));
 | 
						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);
 | 
						*value = *((double*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_string(const struct spa_pod *pod)
 | 
					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);
 | 
						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 void *body, const char **value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const char *s;
 | 
						const char *s = (const char *)body;
 | 
				
			||||||
	if (!spa_pod_is_string(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	s = (const char *)body;
 | 
					 | 
				
			||||||
	if (s[pod->size-1] != '\0')
 | 
						if (s[pod->size-1] != '\0')
 | 
				
			||||||
		return -EINVAL;
 | 
							s = NULL;
 | 
				
			||||||
	*value = s;
 | 
						*value = s;
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_body_copy_string(const struct spa_pod *pod, const void *body,
 | 
					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;
 | 
						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;
 | 
							return -EINVAL;
 | 
				
			||||||
	strncpy(dest, s, maxlen-1);
 | 
						strncpy(dest, s, maxlen-1);
 | 
				
			||||||
	dest[maxlen-1]= '\0';
 | 
						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);
 | 
						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)
 | 
							const void **value, uint32_t *len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_bytes(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	*value = (const void *)body;
 | 
						*value = (const void *)body;
 | 
				
			||||||
	*len = pod->size;
 | 
						*len = pod->size;
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_pointer(const struct spa_pod *pod)
 | 
					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));
 | 
						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)
 | 
							uint32_t *type, const void **value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_pointer(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	*type = ((struct spa_pod_pointer_body*)body)->type;
 | 
						*type = ((struct spa_pod_pointer_body*)body)->type;
 | 
				
			||||||
	*value = ((struct spa_pod_pointer_body*)body)->value;
 | 
						*value = ((struct spa_pod_pointer_body*)body)->value;
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_fd(const struct spa_pod *pod)
 | 
					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));
 | 
						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)
 | 
							int64_t *value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_fd(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	*value = *((int64_t*)body);
 | 
						*value = *((int64_t*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_rectangle(const struct spa_pod *pod)
 | 
					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));
 | 
						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)
 | 
							struct spa_rectangle *value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_rectangle(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	*value = *((struct spa_rectangle*)body);
 | 
						*value = *((struct spa_rectangle*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_fraction(const struct spa_pod *pod)
 | 
					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));
 | 
						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)
 | 
							struct spa_fraction *value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_fraction(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	*value = *((struct spa_fraction*)body);
 | 
						*value = *((struct spa_fraction*)body);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_API_POD_BODY int spa_pod_is_bitmap(const struct spa_pod *pod)
 | 
					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));
 | 
						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)
 | 
					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));
 | 
						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)
 | 
							struct spa_pod_array *arr, const void **arr_body)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_array(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	arr->pod = *pod;
 | 
						arr->pod = *pod;
 | 
				
			||||||
	memcpy(&arr->body, body, sizeof(struct spa_pod_array_body));
 | 
						memcpy(&arr->body, body, sizeof(struct spa_pod_array_body));
 | 
				
			||||||
	*arr_body = SPA_PTROFF(body, sizeof(struct spa_pod_array_body), void);
 | 
						*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,
 | 
					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)
 | 
							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)
 | 
							const void *body, uint32_t *n_values, uint32_t *val_size, uint32_t *val_type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct spa_pod_array arr;
 | 
						struct spa_pod_array arr;
 | 
				
			||||||
	if (spa_pod_body_get_array(pod, body, &arr, &body) < 0)
 | 
						spa_pod_body_get_array(pod, body, &arr, &body);
 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	return spa_pod_array_body_get_values(&arr, body, n_values, val_size, val_type);
 | 
						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));
 | 
						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)
 | 
							struct spa_pod_choice *choice, const void **choice_body)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_choice(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	choice->pod = *pod;
 | 
						choice->pod = *pod;
 | 
				
			||||||
	memcpy(&choice->body, body, sizeof(struct spa_pod_choice_body));
 | 
						memcpy(&choice->body, body, sizeof(struct spa_pod_choice_body));
 | 
				
			||||||
	*choice_body = SPA_PTROFF(body, sizeof(struct spa_pod_choice_body), void);
 | 
						*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,
 | 
					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,
 | 
							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));
 | 
						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)
 | 
							struct spa_pod_object *object, const void **object_body)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_object(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	object->pod = *pod;
 | 
						object->pod = *pod;
 | 
				
			||||||
	memcpy(&object->body, body, sizeof(struct spa_pod_object_body));
 | 
						memcpy(&object->body, body, sizeof(struct spa_pod_object_body));
 | 
				
			||||||
	*object_body = SPA_PTROFF(body, sizeof(struct spa_pod_object_body), void);
 | 
						*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)
 | 
					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));
 | 
						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)
 | 
							struct spa_pod_sequence *seq, const void **seq_body)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!spa_pod_is_sequence(pod))
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	seq->pod = *pod;
 | 
						seq->pod = *pod;
 | 
				
			||||||
	memcpy(&seq->body, body, sizeof(struct spa_pod_sequence_body));
 | 
						memcpy(&seq->body, body, sizeof(struct spa_pod_sequence_body));
 | 
				
			||||||
	*seq_body = SPA_PTROFF(body, sizeof(struct spa_pod_sequence_body), void);
 | 
						*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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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)
 | 
					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,
 | 
					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)
 | 
							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);
 | 
						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)
 | 
					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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_bool(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_bool(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_bool(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_id(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_id(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_id(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_int(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_int(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_int(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_long(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_long(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_long(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_float(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_float(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_float(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -261,8 +271,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_double(struct spa_pod_parser *parser,
 | 
				
			||||||
	const void *body;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_double(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_double(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_double(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -273,8 +285,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_string(struct spa_pod_parser *parser,
 | 
				
			||||||
	const void *body;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_string(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_string(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_string(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_bytes(&pod, body, value, len)) >= 0)
 | 
						if (!spa_pod_is_bytes(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_bytes(&pod, body, value, len);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -297,8 +313,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_pointer(struct spa_pod_parser *parser,
 | 
				
			||||||
	const void *body;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_pointer(&pod, body, type, value)) >= 0)
 | 
						if (!spa_pod_is_pointer(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_pointer(&pod, body, type, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_fd(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_fd(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_fd(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -321,8 +341,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_rectangle(struct spa_pod_parser *parse
 | 
				
			||||||
	const void *body;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_rectangle(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_rectangle(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_rectangle(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -333,8 +355,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get_fraction(struct spa_pod_parser *parser
 | 
				
			||||||
	const void *body;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_fraction(&pod, body, value)) >= 0)
 | 
						if (!spa_pod_is_fraction(&pod))
 | 
				
			||||||
		spa_pod_parser_advance(parser, &pod);
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_fraction(&pod, body, value);
 | 
				
			||||||
 | 
						spa_pod_parser_advance(parser, &pod);
 | 
				
			||||||
	return res;
 | 
						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_frame *frame, const struct spa_pod *pod, const void *body,
 | 
				
			||||||
		struct spa_pod_object *object, const void **object_body)
 | 
							struct spa_pod_object *object, const void **object_body)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int res;
 | 
					 | 
				
			||||||
	if (!spa_pod_is_object(pod))
 | 
						if (!spa_pod_is_object(pod))
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	spa_pod_parser_init_pod_body(parser, pod, body);
 | 
						spa_pod_parser_init_pod_body(parser, pod, body);
 | 
				
			||||||
	if ((res = spa_pod_body_get_object(pod, body, object, object_body)) < 0)
 | 
						spa_pod_body_get_object(pod, body, object, object_body);
 | 
				
			||||||
		return res;
 | 
					 | 
				
			||||||
	spa_pod_parser_push(parser, frame, pod, parser->state.offset);
 | 
						spa_pod_parser_push(parser, frame, pod, parser->state.offset);
 | 
				
			||||||
	parser->state.offset += sizeof(struct spa_pod_object);
 | 
						parser->state.offset += sizeof(struct spa_pod_object);
 | 
				
			||||||
	return 0;
 | 
						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;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_object(&pod, body, object, object_body)) < 0)
 | 
						if (!spa_pod_is_object(&pod))
 | 
				
			||||||
		return res;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_object(&pod, body, object, object_body);
 | 
				
			||||||
	spa_pod_parser_push(parser, frame, &pod, parser->state.offset);
 | 
						spa_pod_parser_push(parser, frame, &pod, parser->state.offset);
 | 
				
			||||||
	parser->state.offset += sizeof(struct spa_pod_object);
 | 
						parser->state.offset += sizeof(struct spa_pod_object);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
| 
						 | 
					@ -454,8 +477,9 @@ SPA_API_POD_PARSER int spa_pod_parser_push_sequence_body(struct spa_pod_parser *
 | 
				
			||||||
	const void *body;
 | 
						const void *body;
 | 
				
			||||||
	if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
						if ((res = spa_pod_parser_current_body(parser, &pod, &body)) < 0)
 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	if ((res = spa_pod_body_get_sequence(&pod, body, seq, seq_body)) < 0)
 | 
						if (!spa_pod_is_sequence(&pod))
 | 
				
			||||||
		return res;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						spa_pod_body_get_sequence(&pod, body, seq, seq_body);
 | 
				
			||||||
	spa_pod_parser_push(parser, frame, &pod, parser->state.offset);
 | 
						spa_pod_parser_push(parser, frame, &pod, parser->state.offset);
 | 
				
			||||||
	parser->state.offset += sizeof(struct spa_pod_sequence);
 | 
						parser->state.offset += sizeof(struct spa_pod_sequence);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
| 
						 | 
					@ -508,8 +532,7 @@ SPA_API_POD_PARSER bool spa_pod_parser_body_can_collect(const struct spa_pod *po
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		if (type == 'V')
 | 
							if (type == 'V')
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		if (spa_pod_body_get_choice(pod, body, &choice, &body) < 0)
 | 
							spa_pod_body_get_choice(pod, body, &choice, &body);
 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		if (choice.body.type != SPA_CHOICE_None)
 | 
							if (choice.body.type != SPA_CHOICE_None)
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		pod = &choice.body.child;
 | 
							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 {											\
 | 
					do {											\
 | 
				
			||||||
	switch (_type) {								\
 | 
						switch (_type) {								\
 | 
				
			||||||
	case 'b':									\
 | 
						case 'b':									\
 | 
				
			||||||
		*va_arg(args, bool*) = !!*((int32_t*)(body));				\
 | 
							spa_pod_body_get_bool(pod, body, va_arg(args, bool*));			\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'I':									\
 | 
						case 'I':									\
 | 
				
			||||||
 | 
							spa_pod_body_get_id(pod, body, va_arg(args, uint32_t*));		\
 | 
				
			||||||
 | 
							break;									\
 | 
				
			||||||
	case 'i':									\
 | 
						case 'i':									\
 | 
				
			||||||
		*va_arg(args, int32_t*) = *((int32_t*)(body));				\
 | 
							spa_pod_body_get_int(pod, body, va_arg(args, int32_t*));		\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'l':									\
 | 
						case 'l':									\
 | 
				
			||||||
		*va_arg(args, int64_t*) = *((int64_t*)(body));				\
 | 
							spa_pod_body_get_long(pod, body, va_arg(args, int64_t*));		\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'f':									\
 | 
						case 'f':									\
 | 
				
			||||||
		*va_arg(args, float*) = *((float*)(body));				\
 | 
							spa_pod_body_get_float(pod, body, va_arg(args, float*));		\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'd':									\
 | 
						case 'd':									\
 | 
				
			||||||
		*va_arg(args, double*) = *((double*)(body));				\
 | 
							spa_pod_body_get_double(pod, body, va_arg(args, double*));		\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 's':									\
 | 
						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;									\
 | 
							break;									\
 | 
				
			||||||
 | 
						}										\
 | 
				
			||||||
	case 'S':									\
 | 
						case 'S':									\
 | 
				
			||||||
	{										\
 | 
						{										\
 | 
				
			||||||
		char *dest = va_arg(args, char*);					\
 | 
							char *dest = va_arg(args, char*);					\
 | 
				
			||||||
		uint32_t maxlen = va_arg(args, uint32_t);				\
 | 
							uint32_t maxlen = va_arg(args, uint32_t);				\
 | 
				
			||||||
		maxlen = SPA_MIN(maxlen, (pod)->size);					\
 | 
							spa_pod_body_copy_string(pod, body, dest, maxlen);			\
 | 
				
			||||||
		strncpy(dest, (char *)(body), maxlen-1);					\
 | 
					 | 
				
			||||||
		dest[maxlen-1] = '\0';							\
 | 
					 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	}										\
 | 
						}										\
 | 
				
			||||||
	case 'y':									\
 | 
						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;									\
 | 
							break;									\
 | 
				
			||||||
 | 
						}										\
 | 
				
			||||||
	case 'R':									\
 | 
						case 'R':									\
 | 
				
			||||||
		*va_arg(args, struct spa_rectangle*) =					\
 | 
							spa_pod_body_get_rectangle(pod, body,					\
 | 
				
			||||||
				*((struct spa_rectangle*)(body));				\
 | 
									va_arg(args, struct spa_rectangle*));			\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'F':									\
 | 
						case 'F':									\
 | 
				
			||||||
		*va_arg(args, struct spa_fraction*) =					\
 | 
							spa_pod_body_get_fraction(pod, body,					\
 | 
				
			||||||
				*((struct spa_fraction*)(body));				\
 | 
									va_arg(args, struct spa_fraction*));			\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'B':									\
 | 
						case 'B':									\
 | 
				
			||||||
		*va_arg(args, uint32_t **) = (uint32_t*)(body);				\
 | 
							spa_pod_body_get_bitmap(pod, body, va_arg(args, const uint8_t**));	\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'a':									\
 | 
						case 'a':									\
 | 
				
			||||||
	{										\
 | 
						{										\
 | 
				
			||||||
		struct spa_pod_array_body *b =						\
 | 
							struct spa_pod_array arr; 						\
 | 
				
			||||||
				(struct spa_pod_array_body*)(body);			\
 | 
							uint32_t *val_size = va_arg(args, uint32_t*);				\
 | 
				
			||||||
		uint32_t child_size = b->child.size;					\
 | 
							uint32_t *val_type = va_arg(args, uint32_t*);				\
 | 
				
			||||||
		*va_arg(args, uint32_t*) = child_size;					\
 | 
							uint32_t *n_values = va_arg(args, uint32_t*);				\
 | 
				
			||||||
		*va_arg(args, uint32_t*) = b->child.type;				\
 | 
							const void **arr_body = va_arg(args, const void**);			\
 | 
				
			||||||
		*va_arg(args, uint32_t*) = child_size ? 				\
 | 
							spa_pod_body_get_array(pod, body, &arr, arr_body);			\
 | 
				
			||||||
			((pod)->size - sizeof(struct spa_pod_array_body))/child_size : 0;	\
 | 
							spa_pod_array_body_get_values(&arr, *arr_body,				\
 | 
				
			||||||
		*va_arg(args, void**) = SPA_PTROFF(b,					\
 | 
									n_values, val_size, val_type);				\
 | 
				
			||||||
				sizeof(struct spa_pod_array_body), void);		\
 | 
					 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	}										\
 | 
						}										\
 | 
				
			||||||
	case 'p':									\
 | 
						case 'p':									\
 | 
				
			||||||
	{										\
 | 
						{										\
 | 
				
			||||||
		struct spa_pod_pointer_body *b =					\
 | 
							uint32_t *type = va_arg(args, uint32_t*);				\
 | 
				
			||||||
				(struct spa_pod_pointer_body *)(body);			\
 | 
							const void **value = va_arg(args, const void**);			\
 | 
				
			||||||
		*(va_arg(args, uint32_t *)) = b->type;					\
 | 
							spa_pod_body_get_pointer(pod, body, type, value);			\
 | 
				
			||||||
		*(va_arg(args, const void **)) = b->value;				\
 | 
					 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	}										\
 | 
						}										\
 | 
				
			||||||
	case 'h':									\
 | 
						case 'h':									\
 | 
				
			||||||
		*va_arg(args, int64_t*) = *((int64_t*)(body));				\
 | 
							spa_pod_body_get_fd(pod, body, va_arg(args, int64_t*));			\
 | 
				
			||||||
		break;									\
 | 
							break;									\
 | 
				
			||||||
	case 'P':									\
 | 
						case 'P':									\
 | 
				
			||||||
	case 'T':									\
 | 
						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;
 | 
								struct spa_pod_choice choice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (pod.type == SPA_TYPE_Choice && *format != 'V') {
 | 
								if (pod.type == SPA_TYPE_Choice && *format != 'V') {
 | 
				
			||||||
				if (spa_pod_body_get_choice(&pod, body, &choice, &body) < 0)
 | 
									spa_pod_body_get_choice(&pod, body, &choice, &body);
 | 
				
			||||||
					return -EINVAL;
 | 
					 | 
				
			||||||
				pod = choice.body.child;
 | 
									pod = choice.body.child;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue