14#include <mpix/types.h>
15#include <mpix/utils.h>
17static inline void mpix_ring_free(
struct mpix_ring *ring)
25static inline int mpix_ring_alloc(
struct mpix_ring *ring)
28 if (ring->
buffer == NULL) {
30 if (ring->
buffer == NULL) {
40static inline bool mpix_ring_is_full(
struct mpix_ring *ring)
45static inline bool mpix_ring_is_empty(
struct mpix_ring *ring)
50static inline size_t mpix_ring_free_size(
struct mpix_ring *ring)
64 if (mpix_ring_is_empty(ring)) {
76static inline size_t mpix_ring_used_size(
struct mpix_ring *ring)
90 if (mpix_ring_is_full(ring)) {
104static inline size_t mpix_ring_peek_size(
struct mpix_ring *ring)
124 if (mpix_ring_is_full(ring) && ring->
tail <= ring->
peek) {
131 if (mpix_ring_is_full(ring) && ring->
peek <= ring->
head) {
141static inline size_t mpix_ring_total_used(
struct mpix_ring *ring)
155 if (mpix_ring_is_full(ring)) {
169static inline size_t mpix_ring_total_free(
struct mpix_ring *ring)
171 return ring->
size - mpix_ring_total_used(ring);
174static inline void mpix_ring_reset_peek(
struct mpix_ring *ring)
179static inline uint8_t *mpix_ring_write(
struct mpix_ring *ring,
size_t size)
183 if (mpix_ring_free_size(ring) < size) {
184 MPIX_DBG(
"Not enough room (%zu) for %zu bytes", mpix_ring_free_size(ring), size);
189 mpix_ring_reset_peek(ring);
193static inline uint8_t *mpix_ring_read(
struct mpix_ring *ring,
size_t size)
197 if (mpix_ring_used_size(ring) < size) {
202 mpix_ring_reset_peek(ring);
205 if (mpix_ring_used_size(ring) == 0) {
212static inline uint8_t *mpix_ring_peek(
struct mpix_ring *ring,
size_t size)
216 if (mpix_ring_peek_size(ring) < size) {
void mpix_port_free(void *mem)
Free a buffer allocated with mpix_port_alloc().
void * mpix_port_alloc(size_t size)
Allocate a buffer to use with libmpix.
Ring buffer of pixels.
Definition types.h:86
uint8_t allocated
Definition types.h:100
size_t peek
Definition types.h:96
uint8_t * buffer
Definition types.h:88
size_t head
Definition types.h:92
uint8_t full
Definition types.h:98
size_t size
Definition types.h:90
size_t tail
Definition types.h:94