14#include <mpix/types.h>
15#include <mpix/utils.h>
17static inline void mpix_ring_free(
struct mpix_ring *ring)
26static inline int mpix_ring_alloc(
struct mpix_ring *ring)
29 if (ring->
buffer == NULL) {
31 if (ring->
buffer == NULL) {
39static inline void mpix_ring_set_buffer(
struct mpix_ring *ring, uint8_t *buffer,
size_t size)
46static inline bool mpix_ring_is_full(
struct mpix_ring *ring)
51static inline bool mpix_ring_is_empty(
struct mpix_ring *ring)
56static inline size_t mpix_ring_free_size(
struct mpix_ring *ring)
70 if (mpix_ring_is_empty(ring)) {
82static inline size_t mpix_ring_used_size(
struct mpix_ring *ring)
96 if (mpix_ring_is_full(ring)) {
110static inline size_t mpix_ring_peek_size(
struct mpix_ring *ring)
130 if (mpix_ring_is_full(ring) && ring->
tail <= ring->
peek) {
137 if (mpix_ring_is_full(ring) && ring->
peek <= ring->
head) {
147static inline size_t mpix_ring_total_used(
struct mpix_ring *ring)
161 if (mpix_ring_is_full(ring)) {
175static inline size_t mpix_ring_total_free(
struct mpix_ring *ring)
177 return ring->
size - mpix_ring_total_used(ring);
180static inline void mpix_ring_reset_peek(
struct mpix_ring *ring)
185static inline uint8_t *mpix_ring_write(
struct mpix_ring *ring,
size_t size)
189 if (mpix_ring_free_size(ring) < size) {
190 MPIX_DBG(
"Not enough room (%zu) for %zu bytes", mpix_ring_free_size(ring), size);
195 mpix_ring_reset_peek(ring);
199static inline uint8_t *mpix_ring_read(
struct mpix_ring *ring,
size_t size)
203 if (mpix_ring_used_size(ring) < size) {
208 mpix_ring_reset_peek(ring);
211 if (mpix_ring_used_size(ring) == 0) {
218static inline uint8_t *mpix_ring_peek(
struct mpix_ring *ring,
size_t size)
222 if (mpix_ring_peek_size(ring) < size) {
void * mpix_port_alloc(size_t size, enum mpix_mem_source mem_source)
Allocate a buffer to use with libmpix.
void mpix_port_free(void *mem, enum mpix_mem_source mem_source)
Free a buffer allocated with mpix_port_alloc().
@ MPIX_MEM_SOURCE_USER
Definition types.h:92
Ring buffer of pixels.
Definition types.h:114
size_t peek
Definition types.h:124
uint8_t * buffer
Definition types.h:116
size_t head
Definition types.h:120
uint8_t full
Definition types.h:128
size_t size
Definition types.h:118
size_t tail
Definition types.h:122
enum mpix_mem_source mem_source
Definition types.h:126