spa/buffer: rename SPA_MEMBER to SPA_PTROFF

SPA_MEMBER is misleading, all we're doing here is pointer+offset and a
type-casting the result. Rename to SPA_PTROFF which is more expressive (and
has the same number of characters so we don't need to re-indent).
This commit is contained in:
Peter Hutterer 2021-05-06 13:41:44 +10:00 committed by Wim Taymans
parent e598d0a422
commit 2405f0942b
92 changed files with 248 additions and 227 deletions

View file

@ -209,7 +209,7 @@ static int on_source_ready(void *_data, int status)
MAP_PRIVATE, datas[0].fd, 0);
if (map == MAP_FAILED)
return -errno;
sdata = SPA_MEMBER(map, datas[0].mapoffset, uint8_t);
sdata = SPA_PTROFF(map, datas[0].mapoffset, uint8_t);
} else if (datas[0].type == SPA_DATA_MemPtr) {
map = NULL;
sdata = datas[0].data;

View file

@ -202,7 +202,7 @@ static int on_source_ready(void *_data, int status)
MAP_PRIVATE, datas[0].fd, 0);
if (map == MAP_FAILED)
return -errno;
sdata = SPA_MEMBER(map, datas[0].mapoffset, uint8_t);
sdata = SPA_PTROFF(map, datas[0].mapoffset, uint8_t);
} else if (datas[0].type == SPA_DATA_MemPtr) {
map = NULL;
sdata = datas[0].data;

View file

@ -202,11 +202,11 @@ spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info,
struct spa_chunk *cp;
b->n_metas = info->n_metas;
b->metas = SPA_MEMBER(b, sizeof(struct spa_buffer), struct spa_meta);
b->metas = SPA_PTROFF(b, sizeof(struct spa_buffer), struct spa_meta);
b->n_datas = info->n_datas;
b->datas = SPA_MEMBER(b->metas, info->n_metas * sizeof(struct spa_meta), struct spa_data);
b->datas = SPA_PTROFF(b->metas, info->n_metas * sizeof(struct spa_meta), struct spa_data);
skel = SPA_MEMBER(b->datas, info->n_datas * sizeof(struct spa_data), void);
skel = SPA_PTROFF(b->datas, info->n_datas * sizeof(struct spa_data), void);
data = data_mem;
if (SPA_FLAG_IS_SET(info->flags, SPA_BUFFER_ALLOC_FLAG_INLINE_META))
@ -218,17 +218,17 @@ spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info,
struct spa_meta *m = &b->metas[i];
*m = info->metas[i];
m->data = *dp;
*dp = SPA_MEMBER(*dp, SPA_ROUND_UP_N(m->size, 8), void);
*dp = SPA_PTROFF(*dp, SPA_ROUND_UP_N(m->size, 8), void);
}
size = info->n_datas * sizeof(struct spa_chunk);
if (SPA_FLAG_IS_SET(info->flags, SPA_BUFFER_ALLOC_FLAG_INLINE_CHUNK)) {
cp = (struct spa_chunk*)skel;
skel = SPA_MEMBER(skel, size, void);
skel = SPA_PTROFF(skel, size, void);
}
else {
cp = (struct spa_chunk*)data;
data = SPA_MEMBER(data, size, void);
data = SPA_PTROFF(data, size, void);
}
if (SPA_FLAG_IS_SET(info->flags, SPA_BUFFER_ALLOC_FLAG_INLINE_DATA))
@ -244,7 +244,7 @@ spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info,
if (!SPA_FLAG_IS_SET(info->flags, SPA_BUFFER_ALLOC_FLAG_NO_DATA)) {
*dp = SPA_PTR_ALIGN(*dp, info->data_aligns[i], void);
d->data = *dp;
*dp = SPA_MEMBER(*dp, d->maxsize, void);
*dp = SPA_PTROFF(*dp, d->maxsize, void);
}
}
return b;
@ -277,8 +277,8 @@ spa_buffer_alloc_layout_array(struct spa_buffer_alloc_info *info,
uint32_t i;
for (i = 0; i < n_buffers; i++) {
buffers[i] = spa_buffer_alloc_layout(info, skel_mem, data_mem);
skel_mem = SPA_MEMBER(skel_mem, info->skel_size, void);
data_mem = SPA_MEMBER(data_mem, info->mem_size, void);
skel_mem = SPA_PTROFF(skel_mem, info->skel_size, void);
data_mem = SPA_PTROFF(data_mem, info->mem_size, void);
}
return 0;
}
@ -322,7 +322,7 @@ spa_buffer_alloc_array(uint32_t n_buffers, uint32_t flags,
if (buffers == NULL)
return NULL;
skel = SPA_MEMBER(buffers, sizeof(struct spa_buffer *) * n_buffers, void);
skel = SPA_PTROFF(buffers, sizeof(struct spa_buffer *) * n_buffers, void);
skel = SPA_PTR_ALIGN(skel, info.max_align, void);
spa_buffer_alloc_layout_array(&info, n_buffers, buffers, skel, NULL);

View file

@ -64,8 +64,8 @@ struct spa_meta {
};
#define spa_meta_first(m) ((m)->data)
#define spa_meta_end(m) SPA_MEMBER((m)->data,(m)->size,void)
#define spa_meta_check(p,m) (SPA_MEMBER(p,sizeof(*p),void) <= spa_meta_end(m))
#define spa_meta_end(m) SPA_PTROFF((m)->data,(m)->size,void)
#define spa_meta_check(p,m) (SPA_PTROFF(p,sizeof(*p),void) <= spa_meta_end(m))
/**
* Describes essential buffer header metadata such as flags and

View file

@ -183,7 +183,7 @@ static inline int spa_debug_format(int indent,
fprintf(stderr, "%s", ssep);
for (i = 1; i < n_vals; i++) {
vals = SPA_MEMBER(vals, size, void);
vals = SPA_PTROFF(vals, size, void);
if (i > 1)
fprintf(stderr, "%s", sep);
spa_debug_format_value(ti ? ti->values : NULL, type, vals, size);

View file

@ -47,7 +47,7 @@ static inline void spa_result_func_device_params(void *data, int seq, int res,
uint32_t offset = d->builder->state.offset;
spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param));
d->data.next = r->next;
d->data.param = SPA_MEMBER(d->builder->data, offset, struct spa_pod);
d->data.param = SPA_PTROFF(d->builder->data, offset, struct spa_pod);
}
static inline int spa_device_enum_params_sync(struct spa_device *device,

View file

@ -48,7 +48,7 @@ static inline void spa_result_func_node_params(void *data,
uint32_t offset = d->builder->state.offset;
spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param));
d->data.next = r->next;
d->data.param = SPA_MEMBER(d->builder->data, offset, struct spa_pod);
d->data.param = SPA_PTROFF(d->builder->data, offset, struct spa_pod);
}
static inline int spa_node_enum_params_sync(struct spa_node *node,

View file

@ -95,7 +95,7 @@ spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
{
uint32_t size = builder->size;
if (offset + 8 <= size) {
struct spa_pod *pod = SPA_MEMBER(builder->data, offset, struct spa_pod);
struct spa_pod *pod = SPA_PTROFF(builder->data, offset, struct spa_pod);
if (offset + SPA_POD_SIZE(pod) <= size)
return pod;
}
@ -106,7 +106,7 @@ static inline struct spa_pod *
spa_pod_builder_frame(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
{
if (frame->offset + SPA_POD_SIZE(&frame->pod) <= builder->size)
return SPA_MEMBER(builder->data, frame->offset, struct spa_pod);
return SPA_PTROFF(builder->data, frame->offset, struct spa_pod);
return NULL;
}
@ -138,7 +138,7 @@ static inline int spa_pod_builder_raw(struct spa_pod_builder *builder, const voi
overflow, 0, offset + size);
}
if (res == 0 && data)
memcpy(SPA_MEMBER(builder->data, offset, void), data, size);
memcpy(SPA_PTROFF(builder->data, offset, void), data, size);
builder->state.offset += size;

View file

@ -50,12 +50,12 @@ static inline int spa_pod_choice_fix_default(struct spa_pod_choice *choice)
case SPA_CHOICE_Range:
case SPA_CHOICE_Step:
if (nvals > 1) {
alt = SPA_MEMBER(alt, size, void);
alt = SPA_PTROFF(alt, size, void);
if (spa_pod_compare_value(type, val, alt, size) < 0)
memcpy(val, alt, size);
}
if (nvals > 2) {
alt = SPA_MEMBER(alt, size, void);
alt = SPA_PTROFF(alt, size, void);
if (spa_pod_compare_value(type, val, alt, size) > 0)
memcpy(val, alt, size);
}
@ -66,7 +66,7 @@ static inline int spa_pod_choice_fix_default(struct spa_pod_choice *choice)
void *best = NULL;
for (i = 1; i < nvals; i++) {
alt = SPA_MEMBER(alt, size, void);
alt = SPA_PTROFF(alt, size, void);
if (spa_pod_compare_value(type, val, alt, size) == 0) {
best = alt;
break;
@ -139,14 +139,14 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
if (p1c == SPA_CHOICE_None || p1c == SPA_CHOICE_Flags) {
nalt1 = 1;
} else {
alt1 = SPA_MEMBER(alt1, size, void);
alt1 = SPA_PTROFF(alt1, size, void);
nalt1--;
}
if (p2c == SPA_CHOICE_None || p2c == SPA_CHOICE_Flags) {
nalt2 = 1;
} else {
alt2 = SPA_MEMBER(alt2, size, void);
alt2 = SPA_PTROFF(alt2, size, void);
nalt2--;
}
@ -164,8 +164,8 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
(p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Enum)) {
int n_copied = 0;
/* copy all equal values but don't copy the default value again */
for (j = 0, a1 = alt1; j < nalt1; j++, a1 = SPA_MEMBER(a1, size, void)) {
for (k = 0, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) {
for (j = 0, a1 = alt1; j < nalt1; j++, a1 = SPA_PTROFF(a1, size, void)) {
for (k = 0, a2 = alt2; k < nalt2; k++, a2 = SPA_PTROFF(a2,size,void)) {
if (spa_pod_compare_value(type, a1, a2, size) == 0) {
if (p1c == SPA_CHOICE_Enum || j > 0)
spa_pod_builder_raw(b, a1, size);
@ -182,10 +182,10 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
(p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Range)) {
int n_copied = 0;
/* copy all values inside the range */
for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 = SPA_MEMBER(a1,size,void)) {
for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 = SPA_PTROFF(a1,size,void)) {
if (spa_pod_compare_value(type, a1, a2, size) < 0)
continue;
if (spa_pod_compare_value(type, a1, SPA_MEMBER(a2,size,void), size) > 0)
if (spa_pod_compare_value(type, a1, SPA_PTROFF(a2,size,void), size) > 0)
continue;
spa_pod_builder_raw(b, a1, size);
n_copied++;
@ -204,10 +204,10 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
(p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Enum)) {
int n_copied = 0;
/* copy all values inside the range */
for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) {
for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 = SPA_PTROFF(a2,size,void)) {
if (spa_pod_compare_value(type, a2, a1, size) < 0)
continue;
if (spa_pod_compare_value(type, a2, SPA_MEMBER(a1,size,void), size) > 0)
if (spa_pod_compare_value(type, a2, SPA_PTROFF(a1,size,void), size) > 0)
continue;
spa_pod_builder_raw(b, a2, size);
n_copied++;
@ -226,8 +226,8 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
else
spa_pod_builder_raw(b, alt1, size);
alt1 = SPA_MEMBER(alt1,size,void);
alt2 = SPA_MEMBER(alt2,size,void);
alt1 = SPA_PTROFF(alt1,size,void);
alt2 = SPA_PTROFF(alt2,size,void);
if (spa_pod_compare_value(type, alt1, alt2, size) < 0)
spa_pod_builder_raw(b, alt1, size);
@ -331,9 +331,9 @@ static inline int spa_pod_filter_part(struct spa_pod_builder *b,
filter_offset = sizeof(struct spa_pod_struct);
spa_pod_builder_push_struct(b, &f);
res = spa_pod_filter_part(b,
SPA_MEMBER(pp,filter_offset,const struct spa_pod),
SPA_PTROFF(pp,filter_offset,const struct spa_pod),
SPA_POD_SIZE(pp) - filter_offset,
SPA_MEMBER(pf,filter_offset,const struct spa_pod),
SPA_PTROFF(pf,filter_offset,const struct spa_pod),
SPA_POD_SIZE(pf) - filter_offset);
spa_pod_builder_pop(b, &f);
do_advance = true;

View file

@ -43,61 +43,61 @@ struct spa_pod_frame {
static inline bool spa_pod_is_inside(const void *pod, uint32_t size, const void *iter)
{
return SPA_POD_BODY(iter) <= SPA_MEMBER(pod, size, void) &&
SPA_MEMBER(iter, SPA_POD_SIZE(iter), void) <= SPA_MEMBER(pod, size, void);
return SPA_POD_BODY(iter) <= SPA_PTROFF(pod, size, void) &&
SPA_PTROFF(iter, SPA_POD_SIZE(iter), void) <= SPA_PTROFF(pod, size, void);
}
static inline void *spa_pod_next(const void *iter)
{
return SPA_MEMBER(iter, SPA_ROUND_UP_N(SPA_POD_SIZE(iter), 8), void);
return SPA_PTROFF(iter, SPA_ROUND_UP_N(SPA_POD_SIZE(iter), 8), void);
}
static inline struct spa_pod_prop *spa_pod_prop_first(const struct spa_pod_object_body *body)
{
return SPA_MEMBER(body, sizeof(struct spa_pod_object_body), struct spa_pod_prop);
return SPA_PTROFF(body, sizeof(struct spa_pod_object_body), struct spa_pod_prop);
}
static inline bool spa_pod_prop_is_inside(const struct spa_pod_object_body *body,
uint32_t size, const struct spa_pod_prop *iter)
{
return SPA_POD_CONTENTS(struct spa_pod_prop, iter) <= SPA_MEMBER(body, size, void) &&
SPA_MEMBER(iter, SPA_POD_PROP_SIZE(iter), void) <= SPA_MEMBER(body, size, void);
return SPA_POD_CONTENTS(struct spa_pod_prop, iter) <= SPA_PTROFF(body, size, void) &&
SPA_PTROFF(iter, SPA_POD_PROP_SIZE(iter), void) <= SPA_PTROFF(body, size, 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);
return SPA_PTROFF(iter, SPA_ROUND_UP_N(SPA_POD_PROP_SIZE(iter), 8), struct spa_pod_prop);
}
static inline struct spa_pod_control *spa_pod_control_first(const struct spa_pod_sequence_body *body)
{
return SPA_MEMBER(body, sizeof(struct spa_pod_sequence_body), struct spa_pod_control);
return SPA_PTROFF(body, sizeof(struct spa_pod_sequence_body), struct spa_pod_control);
}
static inline bool spa_pod_control_is_inside(const struct spa_pod_sequence_body *body,
uint32_t size, const struct spa_pod_control *iter)
{
return SPA_POD_CONTENTS(struct spa_pod_control, iter) <= SPA_MEMBER(body, size, void) &&
SPA_MEMBER(iter, SPA_POD_CONTROL_SIZE(iter), void) <= SPA_MEMBER(body, size, void);
return SPA_POD_CONTENTS(struct spa_pod_control, iter) <= SPA_PTROFF(body, size, void) &&
SPA_PTROFF(iter, SPA_POD_CONTROL_SIZE(iter), void) <= SPA_PTROFF(body, size, void);
}
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);
return SPA_PTROFF(iter, SPA_ROUND_UP_N(SPA_POD_CONTROL_SIZE(iter), 8), struct spa_pod_control);
}
#define SPA_POD_ARRAY_BODY_FOREACH(body, _size, iter) \
for ((iter) = (__typeof__(iter))SPA_MEMBER((body), sizeof(struct spa_pod_array_body), void); \
(iter) < (__typeof__(iter))SPA_MEMBER((body), (_size), void); \
(iter) = (__typeof__(iter))SPA_MEMBER((iter), (body)->child.size, void))
for ((iter) = (__typeof__(iter))SPA_PTROFF((body), sizeof(struct spa_pod_array_body), void); \
(iter) < (__typeof__(iter))SPA_PTROFF((body), (_size), void); \
(iter) = (__typeof__(iter))SPA_PTROFF((iter), (body)->child.size, void))
#define SPA_POD_ARRAY_FOREACH(obj, iter) \
SPA_POD_ARRAY_BODY_FOREACH(&(obj)->body, SPA_POD_BODY_SIZE(obj), iter)
#define SPA_POD_CHOICE_BODY_FOREACH(body, _size, iter) \
for ((iter) = (__typeof__(iter))SPA_MEMBER((body), sizeof(struct spa_pod_choice_body), void); \
(iter) < (__typeof__(iter))SPA_MEMBER((body), (_size), void); \
(iter) = (__typeof__(iter))SPA_MEMBER((iter), (body)->child.size, void))
for ((iter) = (__typeof__(iter))SPA_PTROFF((body), sizeof(struct spa_pod_choice_body), void); \
(iter) < (__typeof__(iter))SPA_PTROFF((body), (_size), void); \
(iter) = (__typeof__(iter))SPA_PTROFF((iter), (body)->child.size, void))
#define SPA_POD_CHOICE_FOREACH(obj, iter) \
SPA_POD_CHOICE_BODY_FOREACH(&(obj)->body, SPA_POD_BODY_SIZE(obj), iter)
@ -132,7 +132,7 @@ static inline void *spa_pod_from_data(void *data, size_t maxsize, off_t offset,
void *pod;
if (size < sizeof(struct spa_pod) || offset + size > maxsize)
return NULL;
pod = SPA_MEMBER(data, offset, void);
pod = SPA_PTROFF(data, offset, void);
if (SPA_POD_SIZE(pod) > size)
return NULL;
return pod;

View file

@ -78,7 +78,7 @@ static inline struct spa_pod *
spa_pod_parser_deref(struct spa_pod_parser *parser, uint32_t offset, uint32_t size)
{
if (offset + 8 <= size) {
struct spa_pod *pod = SPA_MEMBER(parser->data, offset, struct spa_pod);
struct spa_pod *pod = SPA_PTROFF(parser->data, offset, struct spa_pod);
if (offset + SPA_POD_SIZE(pod) <= size)
return pod;
}
@ -87,7 +87,7 @@ spa_pod_parser_deref(struct spa_pod_parser *parser, uint32_t offset, uint32_t si
static inline struct spa_pod *spa_pod_parser_frame(struct spa_pod_parser *parser, struct spa_pod_frame *frame)
{
return SPA_MEMBER(parser->data, frame->offset, struct spa_pod);
return SPA_PTROFF(parser->data, frame->offset, struct spa_pod);
}
static inline void spa_pod_parser_push(struct spa_pod_parser *parser,

View file

@ -37,10 +37,10 @@ extern "C" {
#define SPA_POD_SIZE(pod) (sizeof(struct spa_pod) + 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)
#define SPA_POD_BODY(pod) SPA_MEMBER((pod),sizeof(struct spa_pod),void)
#define SPA_POD_BODY_CONST(pod) SPA_MEMBER((pod),sizeof(struct spa_pod),const void)
#define SPA_POD_CONTENTS(type,pod) SPA_PTROFF((pod),sizeof(type),void)
#define SPA_POD_CONTENTS_CONST(type,pod) SPA_PTROFF((pod),sizeof(type),const void)
#define SPA_POD_BODY(pod) SPA_PTROFF((pod),sizeof(struct spa_pod),void)
#define SPA_POD_BODY_CONST(pod) SPA_PTROFF((pod),sizeof(struct spa_pod),const void)
struct spa_pod {
uint32_t size; /* size of the body */

View file

@ -132,8 +132,19 @@ struct spa_fraction {
x; \
})
#define SPA_MEMBER(b,o,t) ((t*)((uint8_t*)(b) + (int)(o)))
#define SPA_MEMBER_ALIGN(b,o,a,t) SPA_PTR_ALIGN(SPA_MEMBER(b,o,t),a,t)
/**
* Return the address (buffer + offset) as pointer of \a type
*/
#define SPA_PTROFF(ptr_,offset_,type_) ((type_*)((uint8_t*)(ptr_) + (int)(offset_)))
#define SPA_PTROFF_ALIGN(ptr_,offset_,alignment_,type_) \
SPA_PTR_ALIGN(SPA_PTROFF(ptr_,offset_,type_),alignment_,type_)
/**
* Deprecated, use SPA_PTROFF and SPA_PTROFF_ALIGN instead
*/
#define SPA_MEMBER(b,o,t) SPA_PTROFF(b,o,t)
#define SPA_MEMBER_ALIGN(b,o,a,t) SPA_PTROFF_ALIGN(b,o,a,t)
#define SPA_CONTAINER_OF(p,t,m) (t*)((uint8_t*)p - offsetof (t,m))

View file

@ -100,9 +100,9 @@ spa_ringbuffer_read_data(struct spa_ringbuffer *rbuf,
uint32_t offset, void *data, uint32_t len)
{
uint32_t l0 = SPA_MIN(len, size - offset), l1 = len - l0;
spa_memcpy(data, SPA_MEMBER(buffer, offset, void), l0);
spa_memcpy(data, SPA_PTROFF(buffer, offset, void), l0);
if (SPA_UNLIKELY(l1 > 0))
spa_memcpy(SPA_MEMBER(data, l0, void), buffer, l1);
spa_memcpy(SPA_PTROFF(data, l0, void), buffer, l1);
}
/**
@ -150,9 +150,9 @@ spa_ringbuffer_write_data(struct spa_ringbuffer *rbuf,
uint32_t offset, const void *data, uint32_t len)
{
uint32_t l0 = SPA_MIN(len, size - offset), l1 = len - l0;
spa_memcpy(SPA_MEMBER(buffer, offset, void), data, l0);
spa_memcpy(SPA_PTROFF(buffer, offset, void), data, l0);
if (SPA_UNLIKELY(l1 > 0))
spa_memcpy(buffer, SPA_MEMBER(data, l0, void), l1);
spa_memcpy(buffer, SPA_PTROFF(data, l0, void), l1);
}
/**

View file

@ -1004,7 +1004,7 @@ again:
if (SPA_LIKELY(state->use_mmap)) {
for (i = 0; i < b->buf->n_datas; i++) {
dst = SPA_MEMBER(my_areas[i].addr, off * state->frame_size, uint8_t);
dst = SPA_PTROFF(my_areas[i].addr, off * state->frame_size, uint8_t);
src = d[i].data;
spa_memcpy(dst, src + offs, l0);
@ -1016,7 +1016,7 @@ again:
void *bufs[b->buf->n_datas];
for (i = 0; i < b->buf->n_datas; i++)
bufs[i] = SPA_MEMBER(d[i].data, offs, void);
bufs[i] = SPA_PTROFF(d[i].data, offs, void);
snd_pcm_writen(hndl, bufs, l0 / state->frame_size);
if (SPA_UNLIKELY(l1 > 0)) {
for (i = 0; i < b->buf->n_datas; i++)
@ -1127,10 +1127,10 @@ push_frames(struct state *state,
l1 = n_bytes - l0;
for (i = 0; i < b->buf->n_datas; i++) {
src = SPA_MEMBER(my_areas[i].addr, offset * state->frame_size, uint8_t);
src = SPA_PTROFF(my_areas[i].addr, offset * state->frame_size, uint8_t);
spa_memcpy(d[i].data, src, l0);
if (l1 > 0)
spa_memcpy(SPA_MEMBER(d[i].data, l0, void), my_areas[i].addr, l1);
spa_memcpy(SPA_PTROFF(d[i].data, l0, void), my_areas[i].addr, l1);
d[i].chunk->offset = 0;
d[i].chunk->size = n_bytes;
d[i].chunk->stride = state->frame_size;

View file

@ -459,10 +459,10 @@ static void impl_on_notify_events(struct spa_source *source)
if (len <= 0)
break;
e = SPA_MEMBER(&buf, len, void);
e = SPA_PTROFF(&buf, len, void);
for (p = &buf; p < e;
p = SPA_MEMBER(p, sizeof(struct inotify_event) + event->len, void)) {
p = SPA_PTROFF(p, sizeof(struct inotify_event) + event->len, void)) {
unsigned int id;
struct device *device;

View file

@ -1196,7 +1196,7 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_NODE,
&impl_node, this);
this->hnd_convert = SPA_MEMBER(this, sizeof(struct impl), struct spa_handle);
this->hnd_convert = SPA_PTROFF(this, sizeof(struct impl), struct spa_handle);
spa_handle_factory_init(&spa_audioconvert_factory,
this->hnd_convert,
info, support, n_support);

View file

@ -1288,37 +1288,37 @@ impl_init(const struct spa_handle_factory *factory,
this->info.params = this->params;
this->info.n_params = 4;
this->hnd_merger = SPA_MEMBER(this, sizeof(struct impl), struct spa_handle);
this->hnd_merger = SPA_PTROFF(this, sizeof(struct impl), struct spa_handle);
spa_handle_factory_init(&spa_merger_factory,
this->hnd_merger,
info, support, n_support);
size = spa_handle_factory_get_size(&spa_merger_factory, info);
this->hnd_convert_in = SPA_MEMBER(this->hnd_merger, size, struct spa_handle);
this->hnd_convert_in = SPA_PTROFF(this->hnd_merger, size, struct spa_handle);
spa_handle_factory_init(&spa_fmtconvert_factory,
this->hnd_convert_in,
info, support, n_support);
size = spa_handle_factory_get_size(&spa_fmtconvert_factory, info);
this->hnd_channelmix = SPA_MEMBER(this->hnd_convert_in, size, struct spa_handle);
this->hnd_channelmix = SPA_PTROFF(this->hnd_convert_in, size, struct spa_handle);
spa_handle_factory_init(&spa_channelmix_factory,
this->hnd_channelmix,
info, support, n_support);
size = spa_handle_factory_get_size(&spa_channelmix_factory, info);
this->hnd_resample = SPA_MEMBER(this->hnd_channelmix, size, struct spa_handle);
this->hnd_resample = SPA_PTROFF(this->hnd_channelmix, size, struct spa_handle);
spa_handle_factory_init(&spa_resample_factory,
this->hnd_resample,
info, support, n_support);
size = spa_handle_factory_get_size(&spa_resample_factory, info);
this->hnd_convert_out = SPA_MEMBER(this->hnd_resample, size, struct spa_handle);
this->hnd_convert_out = SPA_PTROFF(this->hnd_resample, size, struct spa_handle);
spa_handle_factory_init(&spa_fmtconvert_factory,
this->hnd_convert_out,
info, support, n_support);
size = spa_handle_factory_get_size(&spa_fmtconvert_factory, info);
this->hnd_splitter = SPA_MEMBER(this->hnd_convert_out, size, struct spa_handle);
this->hnd_splitter = SPA_PTROFF(this->hnd_convert_out, size, struct spa_handle);
spa_handle_factory_init(&spa_splitter_factory,
this->hnd_splitter,
info, support, n_support);

View file

@ -891,7 +891,7 @@ static int impl_node_process(void *object)
struct spa_data *sd = &inb->datas[src_remap];
offs = SPA_MIN(sd->chunk->offset, sd->maxsize);
size = SPA_MIN(size, SPA_MIN(sd->maxsize - offs, sd->chunk->size));
src_datas[i] = SPA_MEMBER(sd->data, offs, void);
src_datas[i] = SPA_PTROFF(sd->data, offs, void);
}
n_samples = size / inport->stride;

View file

@ -1267,7 +1267,7 @@ static int impl_node_process(void *object)
sd = &sbuf->buf->datas[0];
src_datas[i] = SPA_MEMBER(sd->data, sd->chunk->offset, void);
src_datas[i] = SPA_PTROFF(sd->data, sd->chunk->offset, void);
n_samples = SPA_MIN(n_samples, sd->chunk->size / inport->stride);

View file

@ -370,13 +370,13 @@ int resample_native_init(struct resample *r)
d->n_phases = n_phases;
d->in_rate = in_rate;
d->out_rate = out_rate;
d->filter = SPA_MEMBER_ALIGN(d, sizeof(struct native_data), 64, float);
d->hist_mem = SPA_MEMBER_ALIGN(d->filter, filter_size, 64, float);
d->history = SPA_MEMBER(d->hist_mem, history_size, float*);
d->filter = SPA_PTROFF_ALIGN(d, sizeof(struct native_data), 64, float);
d->hist_mem = SPA_PTROFF_ALIGN(d->filter, filter_size, 64, float);
d->history = SPA_PTROFF(d->hist_mem, history_size, float*);
d->filter_stride = filter_stride / sizeof(float);
d->filter_stride_os = d->filter_stride * oversample;
for (c = 0; c < r->channels; c++)
d->history[c] = SPA_MEMBER(d->hist_mem, c * history_stride, float);
d->history[c] = SPA_PTROFF(d->hist_mem, c * history_stride, float);
build_filter(d->filter, d->filter_stride, n_taps, n_phases, scale);

View file

@ -849,10 +849,10 @@ static int impl_node_process(void *object)
flush_in = draining = true;
} else {
for (i = 0; i < sb->n_datas; i++)
src_datas[i] = SPA_MEMBER(sb->datas[i].data, inport->offset, void);
src_datas[i] = SPA_PTROFF(sb->datas[i].data, inport->offset, void);
}
for (i = 0; i < db->n_datas; i++)
dst_datas[i] = SPA_MEMBER(db->datas[i].data, outport->offset, void);
dst_datas[i] = SPA_PTROFF(db->datas[i].data, outport->offset, void);
in_len = (size - inport->offset) / sizeof(float);
out_len = (maxsize - outport->offset) / sizeof(float);

View file

@ -920,7 +920,7 @@ static int impl_node_process(void *object)
maxsize = INT_MAX;
for (i = 0; i < n_src_datas; i++) {
src_datas[i] = SPA_MEMBER(sd[i].data,
src_datas[i] = SPA_PTROFF(sd[i].data,
sd[i].chunk->offset, void);
maxsize = SPA_MIN(sd[i].chunk->size, maxsize);
}

View file

@ -658,10 +658,10 @@ add_port_data(struct impl *this, void *out, size_t outsize, struct port *port, i
n_src = 0;
if (layer > 0) {
s0[n_src] = out;
s1[n_src] = SPA_MEMBER(out, len1, void);
s1[n_src] = SPA_PTROFF(out, len1, void);
n_src++;
}
s0[n_src] = SPA_MEMBER(data, offset, void);
s0[n_src] = SPA_PTROFF(data, offset, void);
s1[n_src] = data;
n_src++;
@ -671,7 +671,7 @@ add_port_data(struct impl *this, void *out, size_t outsize, struct port *port, i
else {
mix_ops_process(&this->ops, out, s0, n_src, len1);
if (len2 > 0)
mix_ops_process(&this->ops, SPA_MEMBER(out, len1, void), s1, n_src, len2);
mix_ops_process(&this->ops, SPA_PTROFF(out, len1, void), s1, n_src, len2);
}
port->queued_bytes -= outsize;
@ -733,7 +733,7 @@ static int mix_output(struct impl *this, size_t n_bytes)
continue;
}
add_port_data(this, SPA_MEMBER(od[0].data, offset, void), len1, in_port, layer);
add_port_data(this, SPA_PTROFF(od[0].data, offset, void), len1, in_port, layer);
if (len2 > 0)
add_port_data(this, od[0].data, len2, in_port, layer);
layer++;

View file

@ -401,7 +401,7 @@ static int make_buffer(struct impl *this)
l0 = SPA_MIN(n_bytes, maxsize - offset) / port->bpf;
l1 = n_samples - l0;
port->render_func(this, SPA_MEMBER(data, offset, void), l0);
port->render_func(this, SPA_PTROFF(data, offset, void), l0);
if (l1 > 0)
port->render_func(this, data, l1);

View file

@ -534,7 +534,7 @@ static int codec_start_encode (void *data,
struct impl *this = data;
this->header = (struct rtp_header *)dst;
this->payload = SPA_MEMBER(dst, sizeof(struct rtp_header), struct rtp_payload);
this->payload = SPA_PTROFF(dst, sizeof(struct rtp_header), struct rtp_payload);
memset(this->header, 0, sizeof(struct rtp_header)+sizeof(struct rtp_payload));
this->payload->frame_count = 0;

View file

@ -577,7 +577,7 @@ static int codec_start_encode (void *data,
struct impl *this = data;
this->header = (struct rtp_header *)dst;
this->payload = SPA_MEMBER(dst, sizeof(struct rtp_header), struct rtp_payload);
this->payload = SPA_PTROFF(dst, sizeof(struct rtp_header), struct rtp_payload);
memset(this->header, 0, sizeof(struct rtp_header)+sizeof(struct rtp_payload));
this->payload->frame_count = 0;

View file

@ -509,7 +509,7 @@ static int add_data(struct impl *this, const void *data, uint32_t size)
if (processed <= 0)
return total > 0 ? total : processed;
data = SPA_MEMBER(data, processed, void);
data = SPA_PTROFF(data, processed, void);
size -= processed;
total += processed;
}

View file

@ -1468,7 +1468,7 @@ struct spa_bt_transport *spa_bt_transport_create(struct spa_bt_monitor *monitor,
t->fd = -1;
t->sco_io = NULL;
t->delay = SPA_BT_UNKNOWN_DELAY;
t->user_data = SPA_MEMBER(t, sizeof(struct spa_bt_transport), void);
t->user_data = SPA_PTROFF(t, sizeof(struct spa_bt_transport), void);
spa_hook_list_init(&t->listener_list);
spa_list_append(&monitor->transport_list, &t->link);

View file

@ -120,7 +120,7 @@ static int spa_libcamera_clear_buffers(struct impl *this)
spa_libcamera_buffer_recycle(this, i);
}
if (SPA_FLAG_IS_SET(b->flags, BUFFER_FLAG_MAPPED)) {
munmap(SPA_MEMBER(b->ptr, -d[0].mapoffset, void),
munmap(SPA_PTROFF(b->ptr, -d[0].mapoffset, void),
d[0].maxsize - d[0].mapoffset);
}
if (SPA_FLAG_IS_SET(b->flags, BUFFER_FLAG_ALLOCATED)) {

View file

@ -134,7 +134,7 @@ static void flush_items(struct impl *impl)
struct invoke_item *item;
bool block;
item = SPA_MEMBER(impl->buffer_data, index & (DATAS_SIZE - 1), struct invoke_item);
item = SPA_PTROFF(impl->buffer_data, index & (DATAS_SIZE - 1), struct invoke_item);
block = item->block;
spa_log_trace(impl->log, NAME " %p: flush item %p", impl, item);
@ -183,7 +183,7 @@ loop_invoke(void *object,
l0 = DATAS_SIZE - offset;
item = SPA_MEMBER(impl->buffer_data, offset, struct invoke_item);
item = SPA_PTROFF(impl->buffer_data, offset, struct invoke_item);
item->func = func;
item->seq = seq;
item->size = size;
@ -193,7 +193,7 @@ loop_invoke(void *object,
spa_log_trace(impl->log, NAME " %p: add item %p filled:%d", impl, item, filled);
if (l0 > sizeof(struct invoke_item) + size) {
item->data = SPA_MEMBER(item, sizeof(struct invoke_item), void);
item->data = SPA_PTROFF(item, sizeof(struct invoke_item), void);
item->item_size = SPA_ROUND_UP_N(sizeof(struct invoke_item) + size, 8);
if (l0 < sizeof(struct invoke_item) + item->item_size)
item->item_size = l0;

View file

@ -427,7 +427,7 @@ static int port_get_format(struct impl *this, struct port *port,
if (index > 0)
return 0;
*param = SPA_MEMBER(port->format_buffer, 0, struct spa_pod);
*param = SPA_PTROFF(port->format_buffer, 0, struct spa_pod);
return 1;
}

View file

@ -440,7 +440,7 @@ static int port_get_format(struct impl *this, struct port *port,
if (index > 0)
return 0;
*param = SPA_MEMBER(port->format_buffer, 0, struct spa_pod);
*param = SPA_PTROFF(port->format_buffer, 0, struct spa_pod);
return 1;
}

View file

@ -406,10 +406,10 @@ static void impl_on_notify_events(struct spa_source *source)
if (len <= 0)
break;
e = SPA_MEMBER(&buf, len, void);
e = SPA_PTROFF(&buf, len, void);
for (p = &buf; p < e;
p = SPA_MEMBER(p, sizeof(struct inotify_event) + event->len, void)) {
p = SPA_PTROFF(p, sizeof(struct inotify_event) + event->len, void)) {
unsigned int id;
struct device *device;

View file

@ -893,7 +893,7 @@ impl_init(const struct spa_handle_factory *factory,
spa_hook_list_init(&this->hooks);
#if 0
this->hnd_convert = SPA_MEMBER(this, sizeof(struct impl), struct spa_handle);
this->hnd_convert = SPA_PTROFF(this, sizeof(struct impl), struct spa_handle);
spa_handle_factory_init(&spa_videoconvert_factory,
this->hnd_convert,
info, support, n_support);

View file

@ -648,8 +648,8 @@ static void do_volume(struct impl *this, struct spa_buffer *dbuf, struct spa_buf
uint32_t soffset = sindex % sd[0].maxsize;
uint32_t doffset = dindex % dd[0].maxsize;
src = SPA_MEMBER(sd[0].data, soffset, int16_t);
dst = SPA_MEMBER(dd[0].data, doffset, int16_t);
src = SPA_PTROFF(sd[0].data, soffset, int16_t);
dst = SPA_PTROFF(dd[0].data, doffset, int16_t);
n_bytes = SPA_MIN(towrite, sd[0].maxsize - soffset);
n_bytes = SPA_MIN(n_bytes, dd[0].maxsize - doffset);

View file

@ -133,6 +133,8 @@ static void test_abi(void)
static void test_macros(void)
{
uint8_t ptr[64];
spa_assert(SPA_MIN(1, 2) == 1);
spa_assert(SPA_MIN(1, -2) == -2);
spa_assert(SPA_MAX(1, 2) == 2);
@ -140,6 +142,14 @@ static void test_macros(void)
spa_assert(SPA_CLAMP(23, 1, 16) == 16);
spa_assert(SPA_CLAMP(-1, 1, 16) == 1);
spa_assert(SPA_CLAMP(8, 1, 16) == 8);
/* SPA_MEMBER exists for backwards compatibility but should no
* longer be used, let's make sure it does what we expect it to */
spa_assert(SPA_MEMBER(ptr, 4, void) == SPA_PTROFF(ptr, 4, void));
spa_assert(SPA_MEMBER(ptr, 32, void) == SPA_PTROFF(ptr, 32, void));
spa_assert(SPA_MEMBER(ptr, 0, void) == SPA_PTROFF(ptr, 0, void));
spa_assert(SPA_MEMBER_ALIGN(ptr, 0, 4, void) == SPA_PTROFF_ALIGN(ptr, 0, 4, void));
spa_assert(SPA_MEMBER_ALIGN(ptr, 4, 32, void) == SPA_PTROFF_ALIGN(ptr, 4, 32, void));
}
static void test_result(void)