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
jp9000 2016-12-05 04:31:34 -08:00
parent 7df46d4a8e
commit 3aa6b50fbe
1 changed files with 14 additions and 0 deletions

View File

@ -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