mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
Use types with known sizes where we can, easier to serialize
Add iterator for POD and use it to implement some demarshalling.
This commit is contained in:
parent
23d09d5b60
commit
f92b68c3c3
77 changed files with 839 additions and 695 deletions
|
|
@ -109,8 +109,8 @@ typedef struct {
|
|||
* @height
|
||||
*/
|
||||
typedef struct {
|
||||
int x, y;
|
||||
int width, height;
|
||||
int32_t x, y;
|
||||
int32_t width, height;
|
||||
} SpaMetaVideoCrop;
|
||||
|
||||
/**
|
||||
|
|
@ -130,10 +130,10 @@ typedef struct {
|
|||
*/
|
||||
typedef struct {
|
||||
SpaDataType type;
|
||||
int flags;
|
||||
int32_t flags;
|
||||
int fd;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
int32_t offset;
|
||||
uint32_t size;
|
||||
} SpaMetaShared;
|
||||
|
||||
/**
|
||||
|
|
@ -145,7 +145,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
SpaMetaType type;
|
||||
void *data;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
} SpaMeta;
|
||||
|
||||
/**
|
||||
|
|
@ -155,9 +155,9 @@ typedef struct {
|
|||
* @stride: stride of data if applicable
|
||||
*/
|
||||
typedef struct {
|
||||
off_t offset;
|
||||
size_t size;
|
||||
ssize_t stride;
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
int32_t stride;
|
||||
} SpaChunk;
|
||||
|
||||
/**
|
||||
|
|
@ -172,10 +172,10 @@ typedef struct {
|
|||
*/
|
||||
typedef struct {
|
||||
SpaDataType type;
|
||||
int flags;
|
||||
uint32_t flags;
|
||||
int fd;
|
||||
off_t mapoffset;
|
||||
size_t maxsize;
|
||||
uint32_t mapoffset;
|
||||
uint32_t maxsize;
|
||||
void *data;
|
||||
SpaChunk *chunk;
|
||||
} SpaData;
|
||||
|
|
@ -190,22 +190,17 @@ typedef struct {
|
|||
*/
|
||||
struct _SpaBuffer {
|
||||
uint32_t id;
|
||||
unsigned int n_metas;
|
||||
uint32_t n_metas;
|
||||
SpaMeta *metas;
|
||||
unsigned int n_datas;
|
||||
uint32_t n_datas;
|
||||
SpaData *datas;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned int n_buffers;
|
||||
SpaBuffer **buffers;
|
||||
} SpaBufferArray;
|
||||
|
||||
static inline void *
|
||||
spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type)
|
||||
{
|
||||
unsigned int i;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++)
|
||||
if (b->metas[i].type == type)
|
||||
|
|
@ -213,10 +208,10 @@ spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
static inline uint32_t
|
||||
spa_meta_type_get_size (SpaMetaType type)
|
||||
{
|
||||
static const size_t header_sizes[] = {
|
||||
static const uint32_t header_sizes[] = {
|
||||
0,
|
||||
sizeof (SpaMetaHeader),
|
||||
sizeof (SpaMetaPointer),
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ typedef struct {
|
|||
} SpaDictItem;
|
||||
|
||||
struct _SpaDict {
|
||||
unsigned int n_items;
|
||||
uint32_t n_items;
|
||||
SpaDictItem *items;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ extern "C" {
|
|||
#include <spa/format.h>
|
||||
#include <spa/pod-builder.h>
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push_format (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame,
|
||||
uint32_t media_type,
|
||||
|
|
@ -43,7 +43,7 @@ spa_pod_builder_push_format (SpaPODBuilder *builder,
|
|||
spa_pod_builder_raw (builder, &p, sizeof(p), false));
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_format (SpaPODBuilder *builder,
|
||||
uint32_t media_type,
|
||||
uint32_t media_subtype,
|
||||
|
|
@ -51,7 +51,7 @@ spa_pod_builder_format (SpaPODBuilder *builder,
|
|||
{
|
||||
SpaPODFrame f;
|
||||
va_list args;
|
||||
off_t off;
|
||||
uint32_t off;
|
||||
|
||||
off = spa_pod_builder_push_format (builder, &f, media_type, media_subtype);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ typedef struct _SpaIDMap SpaIDMap;
|
|||
struct _SpaIDMap {
|
||||
/* the total size of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
size_t size;
|
||||
const size_t size;
|
||||
/**
|
||||
* SpaIDMap::info
|
||||
*
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ typedef enum {
|
|||
|
||||
typedef struct {
|
||||
SpaMonitorEventType type;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
} SpaMonitorEvent;
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -126,7 +126,7 @@ struct _SpaMonitor {
|
|||
|
||||
SpaResult (*enum_items) (SpaMonitor *monitor,
|
||||
SpaMonitorItem **item,
|
||||
unsigned int index);
|
||||
uint32_t index);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ typedef enum {
|
|||
|
||||
struct _SpaNodeCommand {
|
||||
SpaNodeCommandType type;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ typedef enum {
|
|||
|
||||
struct _SpaNodeEvent {
|
||||
SpaNodeEventType type;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -270,10 +270,10 @@ struct _SpaNode {
|
|||
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
|
||||
*/
|
||||
SpaResult (*get_n_ports) (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports);
|
||||
uint32_t *n_input_ports,
|
||||
uint32_t *max_input_ports,
|
||||
uint32_t *n_output_ports,
|
||||
uint32_t *max_output_ports);
|
||||
/**
|
||||
* SpaNode::get_port_ids:
|
||||
* @node: a #SpaNode
|
||||
|
|
@ -290,9 +290,9 @@ struct _SpaNode {
|
|||
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
|
||||
*/
|
||||
SpaResult (*get_port_ids) (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t n_output_ports,
|
||||
uint32_t *output_ids);
|
||||
|
||||
/**
|
||||
|
|
@ -350,7 +350,7 @@ struct _SpaNode {
|
|||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
unsigned int index);
|
||||
uint32_t index);
|
||||
/**
|
||||
* SpaNode::port_set_format:
|
||||
* @node: a #SpaNode
|
||||
|
|
@ -459,7 +459,7 @@ struct _SpaNode {
|
|||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
unsigned int n_buffers);
|
||||
uint32_t n_buffers);
|
||||
/**
|
||||
* SpaNode::port_alloc_buffers:
|
||||
* @node: a #SpaNode
|
||||
|
|
@ -499,9 +499,9 @@ struct _SpaNode {
|
|||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
unsigned int n_params,
|
||||
uint32_t n_params,
|
||||
SpaBuffer **buffers,
|
||||
unsigned int *n_buffers);
|
||||
uint32_t *n_buffers);
|
||||
|
||||
/**
|
||||
* SpaNode::port_set_input:
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ struct _SpaHandleFactory {
|
|||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support);
|
||||
uint32_t n_support);
|
||||
|
||||
/**
|
||||
* SpaHandle::enum_interface_info:
|
||||
|
|
@ -147,7 +147,7 @@ struct _SpaHandleFactory {
|
|||
*/
|
||||
SpaResult (*enum_interface_info) (const SpaHandleFactory *factory,
|
||||
const SpaInterfaceInfo **info,
|
||||
unsigned int index);
|
||||
uint32_t index);
|
||||
};
|
||||
|
||||
#define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__)
|
||||
|
|
@ -165,7 +165,7 @@ struct _SpaHandleFactory {
|
|||
* #SPA_RESULT_ENUM_END when there are no more factories
|
||||
*/
|
||||
typedef SpaResult (*SpaEnumHandleFactoryFunc) (const SpaHandleFactory **factory,
|
||||
unsigned int index);
|
||||
uint32_t index);
|
||||
|
||||
/**
|
||||
* spa_enum_handle_factory:
|
||||
|
|
@ -179,7 +179,7 @@ typedef SpaResult (*SpaEnumHandleFactoryFunc) (const SpaHandleFactory **factory,
|
|||
* #SPA_RESULT_ENUM_END when there are no more factories
|
||||
*/
|
||||
SpaResult spa_enum_handle_factory (const SpaHandleFactory **factory,
|
||||
unsigned int index);
|
||||
uint32_t index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ extern "C" {
|
|||
typedef struct _SpaPODFrame {
|
||||
struct _SpaPODFrame *parent;
|
||||
SpaPOD pod;
|
||||
off_t ref;
|
||||
uint32_t ref;
|
||||
} SpaPODFrame;
|
||||
|
||||
typedef struct _SpaPODBuilder {
|
||||
void *data;
|
||||
size_t size;
|
||||
off_t offset;
|
||||
uint32_t size;
|
||||
uint32_t offset;
|
||||
SpaPODFrame *stack;
|
||||
off_t (*write) (struct _SpaPODBuilder *builder, off_t ref, const void *data, size_t size);
|
||||
uint32_t (*write) (struct _SpaPODBuilder *builder, uint32_t ref, const void *data, uint32_t size);
|
||||
} SpaPODBuilder;
|
||||
|
||||
#define SPA_POD_BUILDER_DEREF(b,ref,type) SPA_MEMBER ((b)->data, (ref), type)
|
||||
|
|
@ -46,7 +46,7 @@ typedef struct _SpaPODBuilder {
|
|||
static inline void
|
||||
spa_pod_builder_init (SpaPODBuilder *builder,
|
||||
void *data,
|
||||
size_t size)
|
||||
uint32_t size)
|
||||
{
|
||||
builder->data = data;
|
||||
builder->size = size;
|
||||
|
|
@ -71,11 +71,11 @@ spa_pod_builder_in_array (SpaPODBuilder *builder, bool *first)
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame,
|
||||
const SpaPOD *pod,
|
||||
off_t ref)
|
||||
uint32_t ref)
|
||||
{
|
||||
frame->parent = builder->stack;
|
||||
frame->pod = *pod;
|
||||
|
|
@ -113,10 +113,10 @@ spa_pod_builder_pop (SpaPODBuilder *builder,
|
|||
spa_pod_builder_advance (builder, SPA_ROUND_UP_N(builder->offset, 8) - builder->offset, false);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_raw (SpaPODBuilder *builder, const void *data, uint32_t size, bool pad)
|
||||
{
|
||||
off_t ref;
|
||||
uint32_t ref;
|
||||
|
||||
if (builder->write) {
|
||||
ref = builder->write (builder, -1, data, size);
|
||||
|
|
@ -132,29 +132,29 @@ spa_pod_builder_raw (SpaPODBuilder *builder, const void *data, uint32_t size, bo
|
|||
return ref;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_string_body (SpaPODBuilder *builder,
|
||||
const char *str,
|
||||
uint32_t len)
|
||||
{
|
||||
off_t out = spa_pod_builder_raw (builder, str, len + 1 , true);
|
||||
uint32_t out = spa_pod_builder_raw (builder, str, len + 1 , true);
|
||||
if (out != -1)
|
||||
*SPA_MEMBER (builder->data, out + len, char) = '\0';
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_pod (SpaPODBuilder *builder, uint32_t size, uint32_t type)
|
||||
{
|
||||
const SpaPOD p = { size, type };
|
||||
return spa_pod_builder_raw (builder, &p, sizeof (p), false);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_primitive (SpaPODBuilder *builder, const SpaPOD *p)
|
||||
{
|
||||
const void *data;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
bool in_array, first = false;
|
||||
|
||||
in_array = spa_pod_builder_in_array (builder, &first);
|
||||
|
|
@ -168,90 +168,90 @@ spa_pod_builder_primitive (SpaPODBuilder *builder, const SpaPOD *p)
|
|||
return spa_pod_builder_raw (builder, data, size, !in_array);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_bool (SpaPODBuilder *builder, bool val)
|
||||
{
|
||||
const SpaPODBool p = { { sizeof (uint32_t), SPA_POD_TYPE_BOOL }, val ? 1 : 0 };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_uri (SpaPODBuilder *builder, uint32_t val)
|
||||
{
|
||||
const SpaPODURI p = { { sizeof (uint32_t), SPA_POD_TYPE_URI }, val };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_int (SpaPODBuilder *builder, int32_t val)
|
||||
{
|
||||
const SpaPODInt p = { { sizeof (uint32_t), SPA_POD_TYPE_INT }, val };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_long (SpaPODBuilder *builder, int64_t val)
|
||||
{
|
||||
const SpaPODLong p = { { sizeof (val), SPA_POD_TYPE_LONG }, val };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_float (SpaPODBuilder *builder, float val)
|
||||
{
|
||||
const SpaPODFloat p = { { sizeof (val), SPA_POD_TYPE_FLOAT }, val };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_double (SpaPODBuilder *builder, double val)
|
||||
{
|
||||
const SpaPODDouble p = { { sizeof (val), SPA_POD_TYPE_DOUBLE }, val };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_string_len (SpaPODBuilder *builder, const char *str, uint32_t len)
|
||||
{
|
||||
const SpaPODString p = { { len + 1, SPA_POD_TYPE_STRING } };
|
||||
off_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
|
||||
uint32_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
|
||||
if (spa_pod_builder_string_body (builder, str, len) == -1)
|
||||
out = -1;
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_string (SpaPODBuilder *builder, const char *str)
|
||||
{
|
||||
uint32_t len = str ? strlen (str) : 0;
|
||||
return spa_pod_builder_string_len (builder, str ? str : "", len);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_bytes (SpaPODBuilder *builder, const void *bytes, uint32_t len)
|
||||
{
|
||||
const SpaPODBytes p = { { len, SPA_POD_TYPE_BYTES } };
|
||||
off_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
|
||||
uint32_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
|
||||
if (spa_pod_builder_raw (builder, bytes, len, true) == -1)
|
||||
out = -1;
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_rectangle (SpaPODBuilder *builder, uint32_t width, uint32_t height)
|
||||
{
|
||||
const SpaPODRectangle p = { { sizeof (SpaRectangle), SPA_POD_TYPE_RECTANGLE }, { width, height } };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_fraction (SpaPODBuilder *builder, uint32_t num, uint32_t denom)
|
||||
{
|
||||
const SpaPODFraction p = { { sizeof (SpaFraction), SPA_POD_TYPE_FRACTION }, { num, denom } };
|
||||
return spa_pod_builder_primitive (builder, &p.pod);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push_array (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame)
|
||||
{
|
||||
|
|
@ -260,7 +260,7 @@ spa_pod_builder_push_array (SpaPODBuilder *builder,
|
|||
spa_pod_builder_raw (builder, &p, sizeof(p) - sizeof(SpaPOD), false));
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_array (SpaPODBuilder *builder,
|
||||
uint32_t child_size,
|
||||
uint32_t child_type,
|
||||
|
|
@ -271,13 +271,13 @@ spa_pod_builder_array (SpaPODBuilder *builder,
|
|||
{ (uint32_t)(sizeof (SpaPODArrayBody) + n_elems * child_size), SPA_POD_TYPE_ARRAY },
|
||||
{ { child_size, child_type } }
|
||||
};
|
||||
off_t out = spa_pod_builder_raw (builder, &p, sizeof(p), true);
|
||||
uint32_t out = spa_pod_builder_raw (builder, &p, sizeof(p), true);
|
||||
if (spa_pod_builder_raw (builder, elems, child_size * n_elems, true) == -1)
|
||||
out = -1;
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push_struct (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame)
|
||||
{
|
||||
|
|
@ -286,7 +286,7 @@ spa_pod_builder_push_struct (SpaPODBuilder *builder,
|
|||
spa_pod_builder_raw (builder, &p, sizeof(p), false));
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push_object (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame,
|
||||
uint32_t id,
|
||||
|
|
@ -297,7 +297,7 @@ spa_pod_builder_push_object (SpaPODBuilder *builder,
|
|||
spa_pod_builder_raw (builder, &p, sizeof(p), false));
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push_prop (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame,
|
||||
uint32_t key,
|
||||
|
|
@ -315,10 +315,10 @@ spa_pod_builder_propv (SpaPODBuilder *builder,
|
|||
va_list args)
|
||||
{
|
||||
while (propid != 0) {
|
||||
int type, n_alternatives = -1;
|
||||
uint32_t type, n_alternatives = -1;
|
||||
SpaPODProp *prop = NULL;
|
||||
SpaPODFrame f;
|
||||
off_t off;
|
||||
uint32_t off;
|
||||
|
||||
if ((off = spa_pod_builder_push_prop (builder, &f, propid, SPA_POD_PROP_FLAG_READWRITE)) != -1)
|
||||
prop = SPA_MEMBER (builder->data, off, SpaPODProp);
|
||||
|
|
|
|||
177
spa/include/spa/pod-iter.h
Normal file
177
spa/include/spa/pod-iter.h
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_POD_ITER_H__
|
||||
#define __SPA_POD_ITER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/pod.h>
|
||||
|
||||
typedef struct {
|
||||
const void *data;
|
||||
uint32_t size;
|
||||
uint32_t offset;
|
||||
} SpaPODIter;
|
||||
|
||||
static inline void
|
||||
spa_pod_iter_contents (SpaPODIter *iter, const void *data, uint32_t size)
|
||||
{
|
||||
iter->data = data;
|
||||
iter->size = size;
|
||||
iter->offset = 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_iter_struct (SpaPODIter *iter, const void *data, uint32_t size)
|
||||
{
|
||||
if (data == NULL || size < 8 || SPA_POD_SIZE (data) > size || SPA_POD_TYPE (data) != SPA_POD_TYPE_STRUCT)
|
||||
return false;
|
||||
|
||||
spa_pod_iter_contents (iter, SPA_POD_CONTENTS (SpaPODStruct, data),
|
||||
SPA_POD_CONTENTS_SIZE (SpaPODStruct, data));
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_iter_object (SpaPODIter *iter, const void *data, uint32_t size)
|
||||
{
|
||||
if (data == NULL || SPA_POD_SIZE (data) > size || SPA_POD_TYPE (data) != SPA_POD_TYPE_OBJECT)
|
||||
return false;
|
||||
|
||||
spa_pod_iter_contents (iter, SPA_POD_CONTENTS (SpaPODObject, data),
|
||||
SPA_POD_CONTENTS_SIZE (SpaPODObject, data));
|
||||
return true;
|
||||
}
|
||||
static inline bool
|
||||
spa_pod_iter_pod (SpaPODIter *iter, SpaPOD *pod)
|
||||
{
|
||||
void *data;
|
||||
uint32_t size;
|
||||
|
||||
switch (SPA_POD_TYPE (pod)) {
|
||||
case SPA_POD_TYPE_STRUCT:
|
||||
data = SPA_POD_CONTENTS (SpaPODStruct, pod);
|
||||
size = SPA_POD_CONTENTS_SIZE (SpaPODStruct, pod);
|
||||
break;
|
||||
case SPA_POD_TYPE_OBJECT:
|
||||
data = SPA_POD_CONTENTS (SpaPODObject, pod);
|
||||
size = SPA_POD_CONTENTS_SIZE (SpaPODObject, pod);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
spa_pod_iter_contents (iter, data, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_iter_has_next (SpaPODIter *iter)
|
||||
{
|
||||
return (iter->offset + 8 <= iter->size &&
|
||||
SPA_POD_SIZE (SPA_MEMBER (iter->data, iter->offset, SpaPOD)) <= iter->size);
|
||||
}
|
||||
|
||||
static inline SpaPOD *
|
||||
spa_pod_iter_next (SpaPODIter *iter)
|
||||
{
|
||||
SpaPOD *res = SPA_MEMBER (iter->data, iter->offset, SpaPOD);
|
||||
iter->offset += SPA_ROUND_UP_N (SPA_POD_SIZE (res), 8);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_iter_getv (SpaPODIter *iter,
|
||||
uint32_t type,
|
||||
va_list args)
|
||||
{
|
||||
while (type && spa_pod_iter_has_next (iter)) {
|
||||
SpaPOD *pod = spa_pod_iter_next (iter);
|
||||
if (pod->type != type)
|
||||
return false;
|
||||
|
||||
switch (type) {
|
||||
case SPA_POD_TYPE_BOOL:
|
||||
case SPA_POD_TYPE_URI:
|
||||
case SPA_POD_TYPE_INT:
|
||||
*(va_arg (args, int32_t*)) = ((SpaPODInt *)(pod))->value;
|
||||
break;
|
||||
case SPA_POD_TYPE_LONG:
|
||||
*(va_arg (args, int64_t*)) = ((SpaPODLong *)(pod))->value;
|
||||
break;
|
||||
case SPA_POD_TYPE_FLOAT:
|
||||
*(va_arg (args, float*)) = ((SpaPODFloat *)(pod))->value;
|
||||
break;
|
||||
case SPA_POD_TYPE_DOUBLE:
|
||||
*(va_arg (args, double*)) = ((SpaPODDouble *)(pod))->value;
|
||||
break;
|
||||
case SPA_POD_TYPE_STRING:
|
||||
*(va_arg (args, char **)) = SPA_POD_CONTENTS (SpaPODString, pod);
|
||||
break;
|
||||
case SPA_POD_TYPE_RECTANGLE:
|
||||
*(va_arg (args, SpaRectangle *)) = ((SpaPODRectangle *)(pod))->value;
|
||||
break;
|
||||
case SPA_POD_TYPE_FRACTION:
|
||||
*(va_arg (args, SpaFraction *)) = ((SpaPODFraction *)(pod))->value;
|
||||
break;
|
||||
case SPA_POD_TYPE_BITMASK:
|
||||
*(va_arg (args, uint32_t **)) = SPA_POD_CONTENTS (SpaPOD, pod);
|
||||
break;
|
||||
case SPA_POD_TYPE_ARRAY:
|
||||
case SPA_POD_TYPE_STRUCT:
|
||||
case SPA_POD_TYPE_OBJECT:
|
||||
case SPA_POD_TYPE_PROP:
|
||||
*(va_arg (args, SpaPOD **)) = pod;
|
||||
break;
|
||||
case SPA_POD_TYPE_BYTES:
|
||||
*(va_arg (args, void **)) = SPA_POD_CONTENTS (SpaPODBytes, pod);
|
||||
*(va_arg (args, uint32_t *)) = SPA_POD_BODY_SIZE (pod);
|
||||
break;
|
||||
default:
|
||||
case SPA_POD_TYPE_INVALID:
|
||||
return false;
|
||||
}
|
||||
type = va_arg (args, uint32_t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_iter_get (SpaPODIter *iter, uint32_t type, ...)
|
||||
{
|
||||
va_list args;
|
||||
bool res;
|
||||
|
||||
va_start (args, type);
|
||||
res = spa_pod_iter_getv (iter, type, args);
|
||||
va_end (args);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_POD_H__ */
|
||||
|
|
@ -57,6 +57,7 @@ typedef struct {
|
|||
} SpaPOD;
|
||||
|
||||
#define SPA_POD_BODY_SIZE(pod) (((SpaPOD*)(pod))->size)
|
||||
#define SPA_POD_TYPE(pod) (((SpaPOD*)(pod))->type)
|
||||
#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))
|
||||
|
||||
|
|
@ -228,10 +229,10 @@ spa_pod_get_bytes (SpaPOD **pod, const void **val, uint32_t *size)
|
|||
}
|
||||
|
||||
|
||||
#define SPA_POD_ARRAY_BODY_FOREACH(body, size, iter) \
|
||||
for ((iter) = SPA_MEMBER (body, sizeof(SpaPODArrayBody), __typeof__(*iter)); \
|
||||
(iter) < SPA_MEMBER (body, (size), __typeof__(*iter)); \
|
||||
(iter) = SPA_MEMBER ((iter), (body)->child.size, __typeof__(*iter)))
|
||||
#define SPA_POD_ARRAY_BODY_FOREACH(body, _size, iter) \
|
||||
for ((iter) = SPA_MEMBER ((body), sizeof(SpaPODArrayBody), __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); \
|
||||
|
|
@ -255,7 +256,7 @@ spa_pod_get_bytes (SpaPOD **pod, const void **val, uint32_t *size)
|
|||
(iter) = SPA_MEMBER ((iter), (body)->value.size, __typeof__(*iter)))
|
||||
|
||||
static inline SpaPODProp *
|
||||
spa_pod_contents_find_prop (const SpaPOD *pod, off_t offset, uint32_t key)
|
||||
spa_pod_contents_find_prop (const SpaPOD *pod, uint32_t offset, uint32_t key)
|
||||
{
|
||||
SpaPOD *res;
|
||||
SPA_POD_CONTENTS_FOREACH (pod, offset, res) {
|
||||
|
|
|
|||
|
|
@ -53,13 +53,13 @@ typedef enum {
|
|||
|
||||
struct _SpaAllocParam {
|
||||
uint32_t type;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
SpaAllocParam param;
|
||||
size_t minsize;
|
||||
size_t stride;
|
||||
uint32_t minsize;
|
||||
int32_t stride;
|
||||
uint32_t min_buffers;
|
||||
uint32_t max_buffers;
|
||||
uint32_t align;
|
||||
|
|
@ -73,19 +73,19 @@ typedef struct {
|
|||
typedef struct {
|
||||
SpaAllocParam param;
|
||||
SpaMetaType type;
|
||||
size_t minsize;
|
||||
size_t stride;
|
||||
size_t blocks;
|
||||
uint32_t minsize;
|
||||
int32_t stride;
|
||||
uint32_t blocks;
|
||||
uint32_t align;
|
||||
} SpaAllocParamMetaEnableRingbuffer;
|
||||
|
||||
typedef struct {
|
||||
SpaAllocParam param;
|
||||
unsigned int padding_top;
|
||||
unsigned int padding_bottom;
|
||||
unsigned int padding_left;
|
||||
unsigned int padding_right;
|
||||
unsigned int stride_align[4];
|
||||
uint32_t padding_top;
|
||||
uint32_t padding_bottom;
|
||||
uint32_t padding_left;
|
||||
uint32_t padding_right;
|
||||
uint32_t stride_align[4];
|
||||
} SpaAllocParamVideoPadding;
|
||||
|
||||
/**
|
||||
|
|
@ -128,7 +128,7 @@ typedef struct {
|
|||
uint64_t maxbuffering;
|
||||
uint64_t latency;
|
||||
SpaAllocParam **params;
|
||||
unsigned int n_params;
|
||||
uint32_t n_params;
|
||||
SpaDict *extra;
|
||||
} SpaPortInfo;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,20 +33,20 @@ typedef SpaPODObject SpaProps;
|
|||
#define SPA_PROPS_PREFIX SPA_PROPS_URI "#"
|
||||
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_push_props (SpaPODBuilder *builder,
|
||||
SpaPODFrame *frame)
|
||||
{
|
||||
return spa_pod_builder_push_object (builder, frame, 0, 0);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
static inline uint32_t
|
||||
spa_pod_builder_props (SpaPODBuilder *builder,
|
||||
uint32_t propid, ...)
|
||||
{
|
||||
SpaPODFrame f;
|
||||
va_list args;
|
||||
off_t off;
|
||||
uint32_t off;
|
||||
|
||||
off = spa_pod_builder_push_props (builder, &f);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ typedef struct _SpaRingbuffer SpaRingbuffer;
|
|||
#include <spa/barrier.h>
|
||||
|
||||
typedef struct {
|
||||
off_t offset;
|
||||
size_t len;
|
||||
uint32_t offset;
|
||||
uint32_t len;
|
||||
} SpaRingbufferArea;
|
||||
|
||||
/**
|
||||
|
|
@ -47,11 +47,11 @@ typedef struct {
|
|||
* @size_mask: mask if @size is power of 2
|
||||
*/
|
||||
struct _SpaRingbuffer {
|
||||
volatile size_t readindex;
|
||||
volatile size_t writeindex;
|
||||
size_t size;
|
||||
size_t mask;
|
||||
size_t mask2;
|
||||
volatile uint32_t readindex;
|
||||
volatile uint32_t writeindex;
|
||||
uint32_t size;
|
||||
uint32_t mask;
|
||||
uint32_t mask2;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -67,7 +67,7 @@ struct _SpaRingbuffer {
|
|||
*/
|
||||
static inline SpaResult
|
||||
spa_ringbuffer_init (SpaRingbuffer *rbuf,
|
||||
size_t size)
|
||||
uint32_t size)
|
||||
{
|
||||
if (SPA_UNLIKELY ((size & (size - 1)) != 0))
|
||||
return SPA_RESULT_ERROR;
|
||||
|
|
@ -94,11 +94,11 @@ spa_ringbuffer_clear (SpaRingbuffer *rbuf)
|
|||
rbuf->writeindex = 0;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
static inline uint32_t
|
||||
spa_ringbuffer_get_read_offset (SpaRingbuffer *rbuf,
|
||||
size_t *offset)
|
||||
uint32_t *offset)
|
||||
{
|
||||
size_t avail, r;
|
||||
uint32_t avail, r;
|
||||
|
||||
r = rbuf->readindex;
|
||||
*offset = r & rbuf->mask;
|
||||
|
|
@ -117,11 +117,11 @@ spa_ringbuffer_get_read_offset (SpaRingbuffer *rbuf,
|
|||
* Fill @areas with pointers to read from. The total amount of
|
||||
* bytes that can be read can be obtained by summing the areas len fields.
|
||||
*/
|
||||
static inline size_t
|
||||
static inline uint32_t
|
||||
spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf,
|
||||
SpaRingbufferArea areas[2])
|
||||
{
|
||||
size_t avail, end, r;
|
||||
uint32_t avail, end, r;
|
||||
|
||||
avail = spa_ringbuffer_get_read_offset (rbuf, &r);
|
||||
end = r + avail;
|
||||
|
|
@ -144,7 +144,7 @@ spa_ringbuffer_read_data (SpaRingbuffer *rbuf,
|
|||
void *buffer,
|
||||
SpaRingbufferArea areas[2],
|
||||
void *data,
|
||||
size_t size)
|
||||
uint32_t size)
|
||||
{
|
||||
if (SPA_LIKELY (size < areas[0].len))
|
||||
memcpy (data, buffer + areas[0].offset, size);
|
||||
|
|
@ -163,17 +163,17 @@ spa_ringbuffer_read_data (SpaRingbuffer *rbuf,
|
|||
*/
|
||||
static inline void
|
||||
spa_ringbuffer_read_advance (SpaRingbuffer *rbuf,
|
||||
ssize_t len)
|
||||
int32_t len)
|
||||
{
|
||||
spa_barrier_full();
|
||||
rbuf->readindex = (rbuf->readindex + len) & rbuf->mask2;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
static inline uint32_t
|
||||
spa_ringbuffer_get_write_offset (SpaRingbuffer *rbuf,
|
||||
size_t *offset)
|
||||
uint32_t *offset)
|
||||
{
|
||||
size_t avail, w;
|
||||
uint32_t avail, w;
|
||||
|
||||
w = rbuf->writeindex;
|
||||
*offset = w & rbuf->mask;
|
||||
|
|
@ -191,11 +191,11 @@ spa_ringbuffer_get_write_offset (SpaRingbuffer *rbuf,
|
|||
* Fill @areas with pointers to write to. The total amount of
|
||||
* bytes that can be written can be obtained by summing the areas len fields.
|
||||
*/
|
||||
static inline size_t
|
||||
static inline uint32_t
|
||||
spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf,
|
||||
SpaRingbufferArea areas[2])
|
||||
{
|
||||
size_t avail, end, w;
|
||||
uint32_t avail, end, w;
|
||||
|
||||
avail = spa_ringbuffer_get_write_offset (rbuf, &w);
|
||||
end = w + avail;
|
||||
|
|
@ -218,7 +218,7 @@ spa_ringbuffer_write_data (SpaRingbuffer *rbuf,
|
|||
void *buffer,
|
||||
SpaRingbufferArea areas[2],
|
||||
void *data,
|
||||
size_t size)
|
||||
uint32_t size)
|
||||
{
|
||||
if (SPA_LIKELY (size < areas[0].len))
|
||||
memcpy (buffer + areas[0].offset, data, size);
|
||||
|
|
@ -238,7 +238,7 @@ spa_ringbuffer_write_data (SpaRingbuffer *rbuf,
|
|||
*/
|
||||
static inline void
|
||||
spa_ringbuffer_write_advance (SpaRingbuffer *rbuf,
|
||||
ssize_t len)
|
||||
int32_t len)
|
||||
{
|
||||
spa_barrier_write();
|
||||
rbuf->writeindex = (rbuf->writeindex + len) & rbuf->mask2;
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ struct _SpaVideoInfoRaw {
|
|||
SpaRectangle size;
|
||||
SpaFraction framerate;
|
||||
SpaFraction max_framerate;
|
||||
unsigned int views;
|
||||
uint32_t views;
|
||||
SpaVideoInterlaceMode interlace_mode;
|
||||
SpaFraction pixel_aspect_ratio;
|
||||
SpaVideoMultiviewMode multiview_mode;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue