libobs/util: Add circlebuf_push_front function
parent
5be855e852
commit
c6914fda45
|
@ -168,6 +168,27 @@ static inline void circlebuf_push_back(struct circlebuf *cb, const void *data,
|
|||
cb->end_pos = new_end_pos;
|
||||
}
|
||||
|
||||
static inline void circlebuf_push_front(struct circlebuf *cb, const void *data,
|
||||
size_t size)
|
||||
{
|
||||
cb->size += size;
|
||||
circlebuf_ensure_capacity(cb);
|
||||
|
||||
if (cb->start_pos < size) {
|
||||
size_t back_size = size - cb->start_pos;
|
||||
|
||||
if (cb->start_pos)
|
||||
memcpy(cb->data, (uint8_t*)data + back_size,
|
||||
cb->start_pos);
|
||||
|
||||
cb->start_pos = cb->capacity - back_size;
|
||||
memcpy((uint8_t*)cb->data + cb->start_pos, data, back_size);
|
||||
} else {
|
||||
cb->start_pos -= size;
|
||||
memcpy((uint8_t*)cb->data + cb->start_pos, data, size);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void circlebuf_peek_front(struct circlebuf *cb, void *data,
|
||||
size_t size)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue