mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-09 13:30:06 -05:00
Format: implement intersection and fixate
This commit is contained in:
parent
9dd826136d
commit
7a7ede96e5
11 changed files with 205 additions and 195 deletions
|
|
@ -35,10 +35,11 @@ spa_pod_builder_push_format (SpaPODBuilder *builder,
|
|||
uint32_t media_type,
|
||||
uint32_t media_subtype)
|
||||
{
|
||||
const SpaFormat p = { { { sizeof (SpaPODObjectBody) + sizeof (SpaFormatBody), SPA_POD_TYPE_OBJECT }, { 0, 0 } },
|
||||
{ { { sizeof (uint32_t), SPA_POD_TYPE_INT }, media_type },
|
||||
{ { sizeof (uint32_t), SPA_POD_TYPE_INT }, media_subtype } } };
|
||||
return spa_pod_builder_push (builder, frame, &p.obj.pod,
|
||||
const SpaFormat p = { { sizeof (SpaFormatBody), SPA_POD_TYPE_OBJECT },
|
||||
{ { 0, 0 },
|
||||
{ { sizeof (uint32_t), SPA_POD_TYPE_INT }, media_type }, 0,
|
||||
{ { sizeof (uint32_t), SPA_POD_TYPE_INT }, media_subtype }, 0 } };
|
||||
return spa_pod_builder_push (builder, frame, &p.pod,
|
||||
spa_pod_builder_raw (builder, &p, sizeof(p), false));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,11 @@ typedef enum {
|
|||
} SpaFormatProps;
|
||||
|
||||
typedef struct {
|
||||
SpaPODInt media_type;
|
||||
SpaPODInt media_subtype;
|
||||
SpaPODObjectBody obj_body;
|
||||
SpaPODInt media_type;
|
||||
uint32_t pad1;
|
||||
SpaPODInt media_subtype;
|
||||
uint32_t pad2;
|
||||
/* contents follow, series of SpaPODProp */
|
||||
} SpaFormatBody;
|
||||
|
||||
|
|
@ -102,7 +105,7 @@ typedef struct {
|
|||
* @pod: POD object with properties
|
||||
*/
|
||||
struct _SpaFormat {
|
||||
SpaPODObject obj;
|
||||
SpaPOD pod;
|
||||
SpaFormatBody body;
|
||||
};
|
||||
|
||||
|
|
@ -111,22 +114,23 @@ struct _SpaFormat {
|
|||
(iter) < SPA_MEMBER ((body), (size), SpaPODProp); \
|
||||
(iter) = SPA_MEMBER ((iter), SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), SpaPODProp))
|
||||
|
||||
#define SPA_FORMAT_FOREACH(format, iter) \
|
||||
SPA_FORMAT_BODY_FOREACH(&format->body, SPA_POD_BODY_SIZE(format), iter)
|
||||
|
||||
static inline SpaPODProp *
|
||||
spa_format_find_prop (const SpaFormat *format, uint32_t key)
|
||||
{
|
||||
SpaPODProp *res;
|
||||
SPA_FORMAT_BODY_FOREACH (&format->body, SPA_POD_BODY_SIZE (format), res) {
|
||||
if (res->pod.type == SPA_POD_TYPE_PROP && res->body.key == key)
|
||||
return res;
|
||||
}
|
||||
return NULL;
|
||||
return spa_pod_contents_find_prop (&format->pod, sizeof (SpaFormat), key);
|
||||
}
|
||||
|
||||
static inline SpaResult
|
||||
spa_format_fixate (SpaFormat *format)
|
||||
{
|
||||
if (format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
SpaPODProp *prop;
|
||||
|
||||
SPA_FORMAT_FOREACH (format, prop)
|
||||
prop->body.flags &= ~SPA_POD_PROP_FLAG_UNSET;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ typedef struct {
|
|||
|
||||
#define SPA_POD_BODY_SIZE(pod) (((SpaPOD*)(pod))->size)
|
||||
#define SPA_POD_SIZE(pod) (sizeof(SpaPOD) + SPA_POD_BODY_SIZE(pod))
|
||||
#define SPA_POD_CONTENTS_SIZE(type,pod) (SPA_POD_SIZE(pod)-sizeof(type))
|
||||
|
||||
#define SPA_POD_CONTENTS(type,pod) SPA_MEMBER((pod),sizeof(type),void)
|
||||
#define SPA_POD_CONTENTS_CONST(type,pod) SPA_MEMBER((pod),sizeof(type),const void)
|
||||
|
|
@ -164,37 +165,44 @@ typedef struct {
|
|||
(iter) < SPA_MEMBER (body, (size), __typeof__(*iter)); \
|
||||
(iter) = SPA_MEMBER ((iter), (body)->child.size, __typeof__(*iter)))
|
||||
|
||||
#define SPA_POD_STRUCT_BODY_FOREACH(body, size, iter) \
|
||||
for ((iter) = SPA_MEMBER ((body), 0, SpaPOD); \
|
||||
(iter) < SPA_MEMBER ((body), (size), SpaPOD); \
|
||||
#define SPA_POD_FOREACH(pod, size, iter) \
|
||||
for ((iter) = (pod); \
|
||||
(iter) < SPA_MEMBER ((pod), (size), SpaPOD); \
|
||||
(iter) = SPA_MEMBER ((iter), SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), SpaPOD))
|
||||
|
||||
#define SPA_POD_FOREACH(pod, iter) \
|
||||
for ((iter) = SPA_POD_CONTENTS(__typeof__(*pod), pod); \
|
||||
(iter) < SPA_MEMBER ((pod), SPA_POD_SIZE (pod), __typeof__(*iter)); \
|
||||
(iter) = SPA_MEMBER ((iter), SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), __typeof__(*iter)))
|
||||
#define SPA_POD_CONTENTS_FOREACH(pod, offset, iter) \
|
||||
SPA_POD_FOREACH(SPA_MEMBER ((pod), (offset), SpaPOD),SPA_POD_SIZE (pod),iter)
|
||||
|
||||
#define SPA_POD_OBJECT_BODY_FOREACH(body, size, iter) \
|
||||
for ((iter) = SPA_MEMBER ((body), sizeof (SpaPODObjectBody), SpaPODProp); \
|
||||
(iter) < SPA_MEMBER ((body), (size), SpaPODProp); \
|
||||
(iter) = SPA_MEMBER ((iter), SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), SpaPODProp))
|
||||
|
||||
#define SPA_POD_OBJECT_FOREACH(obj, iter) \
|
||||
SPA_POD_OBJECT_BODY_FOREACH(&obj->body, SPA_POD_BODY_SIZE(obj), iter)
|
||||
|
||||
#define SPA_POD_PROP_ALTERNATIVE_FOREACH(body, _size, iter) \
|
||||
for ((iter) = SPA_MEMBER ((body), (body)->value.size + sizeof (SpaPODPropBody), __typeof__(*iter)); \
|
||||
(iter) < SPA_MEMBER ((body), (_size), __typeof__(*iter)); \
|
||||
(iter) = SPA_MEMBER ((iter), (body)->value.size, __typeof__(*iter)))
|
||||
|
||||
static inline SpaPODProp *
|
||||
spa_pod_object_find_prop (const SpaPODObject *obj, uint32_t key)
|
||||
spa_pod_contents_find_prop (const SpaPOD *pod, off_t offset, uint32_t key)
|
||||
{
|
||||
SpaPODProp *res;
|
||||
SPA_POD_FOREACH (obj, res) {
|
||||
if (res->pod.type == SPA_POD_TYPE_PROP && res->body.key == key)
|
||||
return res;
|
||||
SpaPOD *res;
|
||||
SPA_POD_CONTENTS_FOREACH (pod, offset, res) {
|
||||
if (res->type == SPA_POD_TYPE_PROP && ((SpaPODProp*)res)->body.key == key)
|
||||
return (SpaPODProp *)res;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline SpaPODProp *
|
||||
spa_pod_object_find_prop (const SpaPODObject *obj, uint32_t key)
|
||||
{
|
||||
return spa_pod_contents_find_prop (&obj->pod, sizeof (SpaPODObject), key);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue