libobs/util: Add circlebuf_push_front function

master
jp9000 2015-12-15 14:10:37 -08:00
parent 5be855e852
commit c6914fda45
1 changed files with 21 additions and 0 deletions

View File

@ -168,6 +168,27 @@ static inline void circlebuf_push_back(struct circlebuf *cb, const void *data,
cb->end_pos = new_end_pos; 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, static inline void circlebuf_peek_front(struct circlebuf *cb, void *data,
size_t size) size_t size)
{ {