ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
ringbuffer.h File Reference

Lock-Free Ring Buffer and Frame Buffer Management. More...

Go to the source code of this file.

Data Structures

struct  ringbuffer_t
 Audio ring buffer for real-time audio streaming. More...
struct  audio_ring_buffer
 Audio ring buffer for real-time audio streaming. More...
struct  frame_t
 One variable-length payload in the video ring buffer. More...
struct  multi_source_frame_t
 One variable-length payload in the video ring buffer. More...
struct  framebuffer_t
 Mutex-protected ring buffer used to exchange video frames. More...

Macros

Audio Ring Buffer Constants

Owns the temporary storage used by ringbuffer. The data pointers and size or cursor fields describe the live portion of the allocation; callers must use the type's cleanup path when the buffer or queue is no longer needed.

#define AUDIO_RING_BUFFER_SIZE   192000
 Audio ring buffer size in samples (192000 samples = 4 seconds @ 48kHz).
#define AUDIO_JITTER_BUFFER_THRESHOLD   4800
 Jitter buffer threshold - samples needed before starting playback.
#define AUDIO_JITTER_LOW_WATER_MARK   2400
 Low water mark - warn when available drops below this.
#define AUDIO_JITTER_HIGH_WATER_MARK   (AUDIO_JITTER_BUFFER_THRESHOLD * 2)
 High water mark - drop OLD samples when buffer exceeds this.
#define AUDIO_JITTER_TARGET_LEVEL   (AUDIO_JITTER_BUFFER_THRESHOLD + 480)
 Target buffer level after dropping old samples.
#define AUDIO_CROSSFADE_SAMPLES   256
 Crossfade duration in samples for smooth underrun recovery.
Frame Magic Numbers
#define FRAME_MAGIC   MAGIC_FRAME_VALID
 Magic number indicating a valid frame (0xDEADBEEF) - Alias for backward compatibility.
#define FRAME_FREED   MAGIC_FRAME_FREED
 Magic number indicating a freed frame (0xFEEDFACE) - Alias for backward compatibility.

Typedefs

typedef struct audio_ring_buffer audio_ring_buffer_t
 Audio ring buffer for real-time audio streaming.

Functions

ringbuffer_t * ringbuffer_create (size_t element_size, size_t capacity)
 Create a new ring buffer.
void ringbuffer_destroy (ringbuffer_t *rb)
 Destroy a ring buffer and free its memory.
bool ringbuffer_write (ringbuffer_t *rb, const void *data)
 Try to write an element to the ring buffer (non-blocking).
bool ringbuffer_read (ringbuffer_t *rb, void *data)
 Try to read an element from the ring buffer (non-blocking).
bool ringbuffer_peek (ringbuffer_t *rb, void *data)
 Peek at the next element without removing it.
size_t ringbuffer_size (const ringbuffer_t *rb)
 Get current number of elements in the buffer.
bool ringbuffer_is_empty (const ringbuffer_t *rb)
 Check if buffer is empty.
bool ringbuffer_is_full (const ringbuffer_t *rb)
 Check if buffer is full.
void ringbuffer_clear (ringbuffer_t *rb)
 Clear all elements from the buffer.
framebuffer_t * framebuffer_create (size_t capacity)
 Mutex-protected ring buffer used to exchange video frames.
framebuffer_t * framebuffer_create_multi (size_t capacity)
 Create a multi-source frame buffer for multi-user support.
void framebuffer_destroy (framebuffer_t *fb)
 Destroy a frame buffer.
bool framebuffer_write_frame (framebuffer_t *fb, const char *frame_data, size_t frame_size)
 Write a frame to the buffer.
bool framebuffer_read_frame (framebuffer_t *fb, frame_t *frame)
 Read a frame from the buffer.
void framebuffer_clear (framebuffer_t *fb)
 Clear all frames from the buffer, freeing their data.
bool framebuffer_write_multi_frame (framebuffer_t *fb, const char *frame_data, size_t frame_size, uint32_t source_client_id, uint32_t frame_sequence, uint32_t timestamp)
 Write a multi-source frame to the buffer (for multi-user support).
bool framebuffer_read_multi_frame (framebuffer_t *fb, multi_source_frame_t *frame)
 Read a multi-source frame from the buffer.
bool framebuffer_peek_latest_multi_frame (framebuffer_t *fb, multi_source_frame_t *frame)
 Peek at the latest multi-source frame without removing it.

Detailed Description

Lock-Free Ring Buffer and Frame Buffer Management.

Definition in file ringbuffer.h.