libobs/util: Add function to get circlebuf data offset
Allows getting pointer to an offset at a specific index within the circlebuf data. Useful for iterating through circlebuf data.master
parent
7df46d4a8e
commit
3aa6b50fbe
|
@ -254,6 +254,20 @@ static inline void circlebuf_pop_back(struct circlebuf *cb, void *data,
|
|||
cb->end_pos -= size;
|
||||
}
|
||||
|
||||
static inline void *circlebuf_data(struct circlebuf *cb, size_t idx)
|
||||
{
|
||||
uint8_t *ptr = cb->data;
|
||||
size_t offset = cb->start_pos + idx;
|
||||
|
||||
if (idx > cb->size)
|
||||
return NULL;
|
||||
|
||||
if (offset >= cb->capacity)
|
||||
offset -= cb->capacity;
|
||||
|
||||
return ptr + offset;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue