meta: make safer find_meta_data function

This commit is contained in:
Wim Taymans 2018-07-09 12:04:23 +02:00
parent 33427b4cd3
commit c98fbfe0a9
16 changed files with 59 additions and 32 deletions

View file

@ -98,17 +98,25 @@ struct spa_buffer {
};
/** Find metadata in a buffer */
static inline void *spa_buffer_find_meta(struct spa_buffer *b, uint32_t type)
static inline struct spa_meta *spa_buffer_find_meta(const struct spa_buffer *b, uint32_t type)
{
uint32_t i;
for (i = 0; i < b->n_metas; i++)
if (b->metas[i].type == type)
return b->metas[i].data;
return &b->metas[i];
return NULL;
}
static inline void *spa_buffer_find_meta_data(const struct spa_buffer *b, uint32_t type, size_t size)
{
struct spa_meta *m;
if ((m = spa_buffer_find_meta(b, type)) && m->size >= size)
return m->data;
return NULL;
}
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -50,6 +50,10 @@ struct spa_meta {
uint32_t size; /**< size of metadata */
};
#define spa_meta_first(m) ((m)->data)
#define spa_meta_end(m) ((m)->data + (m)->size)
#define spa_meta_check(p,m) ((void*)(p) + sizeof(*p) <= spa_meta_end(m))
/**
* Describes essential buffer header metadata such as flags and
* timestamps.