mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
meta: make safer find_meta_data function
This commit is contained in:
parent
33427b4cd3
commit
c98fbfe0a9
16 changed files with 59 additions and 32 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue