ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
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
 Lock-free ring buffer structure. More...
 
struct  audio_ring_buffer
 Audio ring buffer for real-time audio streaming. More...
 
struct  frame_t
 Frame structure that stores both data and actual size. More...
 
struct  multi_source_frame_t
 Multi-source frame structure for multi-user support. More...
 
struct  framebuffer_t
 Frame buffer structure for managing video frames. More...
 

Macros

Audio Ring Buffer Constants
#define AUDIO_RING_BUFFER_SIZE   192000
 Audio ring buffer size in samples (192000 samples = 4 seconds @ 48kHz)
 
#define AUDIO_JITTER_BUFFER_THRESHOLD   960
 Jitter buffer threshold - samples needed before starting playback.
 
#define AUDIO_JITTER_LOW_WATER_MARK   480
 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   0xDEADBEEF
 Magic number indicating a valid frame (0xDEADBEEF)
 
#define FRAME_FREED   0xFEEDFACE
 Magic number indicating a freed frame (0xFEEDFACE)
 

Typedefs

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

Functions

ringbuffer_tringbuffer_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_tframebuffer_create (size_t capacity)
 Create a frame buffer for ASCII frames.
 
framebuffer_tframebuffer_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.