mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-31 11:09:04 -05:00
Type changes
Only allow properties inside objects, this makes it easier to iterate the object, which is needed for efficiently processing control streams. Add a choice type to mark variable properties. SPA_TYPE_Enum -> SPA_TYPE_Id to avoid confusion with choice enum Make it easier to allocate and initialize properties on the stack Make more efficient methods to make objects.
This commit is contained in:
parent
03fdabd155
commit
cc842cbdc8
63 changed files with 2253 additions and 1880 deletions
|
|
@ -69,6 +69,11 @@ static inline void *spa_pod_next(const void *iter)
|
|||
return SPA_MEMBER(iter, SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), void);
|
||||
}
|
||||
|
||||
static inline struct spa_pod_prop *spa_pod_prop_next(const struct spa_pod_prop *iter)
|
||||
{
|
||||
return SPA_MEMBER(iter, SPA_ROUND_UP_N (SPA_POD_PROP_SIZE (iter), 8), struct spa_pod_prop);
|
||||
}
|
||||
|
||||
static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_control *iter)
|
||||
{
|
||||
return SPA_MEMBER(iter, SPA_ROUND_UP_N (SPA_POD_CONTROL_SIZE (iter), 8), struct spa_pod_control);
|
||||
|
|
@ -79,6 +84,11 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_
|
|||
(iter) < SPA_MEMBER((body), (_size), __typeof__(*(iter))); \
|
||||
(iter) = SPA_MEMBER((iter), (body)->child.size, __typeof__(*(iter))))
|
||||
|
||||
#define SPA_POD_CHOICE_BODY_FOREACH(body, _size, iter) \
|
||||
for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_choice_body), __typeof__(*(iter))); \
|
||||
(iter) < SPA_MEMBER((body), (_size), __typeof__(*(iter))); \
|
||||
(iter) = SPA_MEMBER((iter), (body)->child.size, __typeof__(*(iter))))
|
||||
|
||||
#define SPA_POD_FOREACH(pod, size, iter) \
|
||||
for ((iter) = (pod); \
|
||||
spa_pod_is_inside(pod, size, iter); \
|
||||
|
|
@ -88,9 +98,9 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_
|
|||
SPA_POD_FOREACH(SPA_MEMBER((pod), (offset), void),SPA_POD_SIZE (pod)-(offset),iter)
|
||||
|
||||
#define SPA_POD_OBJECT_BODY_FOREACH(body, size, iter) \
|
||||
for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_object_body), struct spa_pod); \
|
||||
for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_object_body), struct spa_pod_prop); \
|
||||
spa_pod_is_inside(body, size, iter); \
|
||||
(iter) = spa_pod_next(iter))
|
||||
(iter) = spa_pod_prop_next(iter))
|
||||
|
||||
#define SPA_POD_OBJECT_FOREACH(obj, iter) \
|
||||
SPA_POD_OBJECT_BODY_FOREACH(&(obj)->body, SPA_POD_BODY_SIZE(obj), iter)
|
||||
|
|
@ -103,56 +113,38 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_
|
|||
#define SPA_POD_SEQUENCE_FOREACH(seq, iter) \
|
||||
SPA_POD_SEQUENCE_BODY_FOREACH(&(seq)->body, SPA_POD_BODY_SIZE(seq), iter)
|
||||
|
||||
#if 0
|
||||
#define SPA_POD_PROP_ALTERNATIVE_FOREACH(body, _size, iter) \
|
||||
for ((iter) = SPA_MEMBER((body), (body)->value.size + \
|
||||
sizeof(struct spa_pod_prop_body), __typeof__(*iter)); \
|
||||
sizeof(struct spa_pod_prop), __typeof__(*iter)); \
|
||||
(iter) <= SPA_MEMBER((body), (_size)-(body)->value.size, __typeof__(*iter)); \
|
||||
(iter) = SPA_MEMBER((iter), (body)->value.size, __typeof__(*iter)))
|
||||
#endif
|
||||
|
||||
static inline struct spa_pod_prop *spa_pod_contents_find_prop(const struct spa_pod *pod,
|
||||
uint32_t size, uint32_t key)
|
||||
static inline struct spa_pod_prop *spa_pod_find_prop(const struct spa_pod *pod, uint32_t key)
|
||||
{
|
||||
const struct spa_pod *res;
|
||||
SPA_POD_FOREACH(pod, size, res) {
|
||||
if (res->type == SPA_TYPE_Prop
|
||||
&& ((struct spa_pod_prop *) res)->body.key == key)
|
||||
return (struct spa_pod_prop *) res;
|
||||
struct spa_pod_prop *res;
|
||||
if (pod->type != SPA_TYPE_Object)
|
||||
return NULL;
|
||||
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)pod, res) {
|
||||
if (res->key == key)
|
||||
return res;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline struct spa_pod_prop *spa_pod_find_prop(const struct spa_pod *pod, uint32_t key)
|
||||
{
|
||||
uint32_t offset;
|
||||
|
||||
if (pod->type == SPA_TYPE_Object)
|
||||
offset = sizeof(struct spa_pod_object);
|
||||
else if (pod->type == SPA_TYPE_Struct)
|
||||
offset = sizeof(struct spa_pod_struct);
|
||||
else
|
||||
return NULL;
|
||||
|
||||
return spa_pod_contents_find_prop(SPA_MEMBER(pod, offset, const struct spa_pod),
|
||||
SPA_POD_SIZE(pod) - offset, key);
|
||||
}
|
||||
|
||||
static inline int spa_pod_fixate(struct spa_pod *pod)
|
||||
{
|
||||
struct spa_pod *res;
|
||||
uint32_t offset;
|
||||
struct spa_pod_prop *res;
|
||||
|
||||
if (pod->type == SPA_TYPE_Object)
|
||||
offset = sizeof(struct spa_pod_object);
|
||||
else if (pod->type == SPA_TYPE_Struct)
|
||||
offset = sizeof(struct spa_pod_struct);
|
||||
else
|
||||
if (pod->type != SPA_TYPE_Object)
|
||||
return -EINVAL;
|
||||
|
||||
SPA_POD_CONTENTS_FOREACH(pod, offset, res) {
|
||||
if (res->type == SPA_TYPE_Prop)
|
||||
SPA_FLAG_UNSET (((struct spa_pod_prop *) res)->body.flags,
|
||||
SPA_POD_PROP_FLAG_UNSET);
|
||||
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)pod, res) {
|
||||
if (res->value.type == SPA_TYPE_Choice)
|
||||
((struct spa_pod_choice*)&res->value)->body.type = SPA_CHOICE_None;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue