74#if defined(__cplusplus) && defined(_WIN32)
76using std::atomic_bool;
78using std::atomic_uint;
135#define AUDIO_RING_BUFFER_SIZE 192000
148#define AUDIO_JITTER_BUFFER_THRESHOLD 960
159#define AUDIO_JITTER_LOW_WATER_MARK 480
172#define AUDIO_JITTER_HIGH_WATER_MARK (AUDIO_JITTER_BUFFER_THRESHOLD * 2)
182#define AUDIO_JITTER_TARGET_LEVEL (AUDIO_JITTER_BUFFER_THRESHOLD + 480)
189#define AUDIO_CROSSFADE_SAMPLES 256
421#define FRAME_MAGIC 0xDEADBEEF
423#define FRAME_FREED 0xFEEDFACE
struct audio_ring_buffer audio_ring_buffer_t
Audio ring buffer for real-time audio streaming.
void ringbuffer_clear(ringbuffer_t *rb)
Clear all elements from the buffer.
void framebuffer_destroy(framebuffer_t *fb)
Destroy a frame buffer.
#define AUDIO_RING_BUFFER_SIZE
Audio ring buffer size in samples (192000 samples = 4 seconds @ 48kHz)
void framebuffer_clear(framebuffer_t *fb)
Clear all frames from the buffer, freeing their data.
bool framebuffer_read_multi_frame(framebuffer_t *fb, multi_source_frame_t *frame)
Read a multi-source frame from the buffer.
framebuffer_t * framebuffer_create_multi(size_t capacity)
Create a multi-source frame buffer for multi-user support.
ringbuffer_t * ringbuffer_create(size_t element_size, size_t capacity)
Create a new ring buffer.
framebuffer_t * framebuffer_create(size_t capacity)
Create a frame buffer for ASCII frames.
size_t ringbuffer_size(const ringbuffer_t *rb)
Get current number of elements in the buffer.
bool framebuffer_read_frame(framebuffer_t *fb, frame_t *frame)
Read a frame from the buffer.
bool ringbuffer_is_full(const ringbuffer_t *rb)
Check if buffer is full.
void ringbuffer_destroy(ringbuffer_t *rb)
Destroy a ring buffer and free its memory.
bool ringbuffer_is_empty(const ringbuffer_t *rb)
Check if buffer is empty.
bool framebuffer_write_frame(framebuffer_t *fb, const char *frame_data, size_t frame_size)
Write a frame to the buffer.
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_peek_latest_multi_frame(framebuffer_t *fb, multi_source_frame_t *frame)
Peek at the latest multi-source frame without removing it.
bool ringbuffer_read(ringbuffer_t *rb, void *data)
Try to read an element from the ring buffer (non-blocking)
bool ringbuffer_write(ringbuffer_t *rb, const void *data)
Try to write an element to the ring buffer (non-blocking)
bool ringbuffer_peek(ringbuffer_t *rb, void *data)
Peek at the next element without removing it.
Cross-platform mutex interface for ascii-chat.
Audio ring buffer for real-time audio streaming.
atomic_uint read_index
Read index (consumer position) - LOCK-FREE with atomic operations.
float last_sample
Last sample value for smooth fade-out during underrun - NOT atomic (only written by reader)
atomic_bool jitter_buffer_filled
True after initial jitter buffer fill.
atomic_uint underrun_count
Count of underrun events for diagnostics.
atomic_int crossfade_samples_remaining
Samples remaining in crossfade (0 = no crossfade active)
mutex_t mutex
Mutex for SLOW PATH only (clear/destroy operations, not regular read/write)
bool jitter_buffer_enabled
Whether jitter buffering is enabled (false for capture, true for playback)
atomic_uint write_index
Write index (producer position) - LOCK-FREE with atomic operations.
float data[192000]
Audio sample data buffer.
atomic_bool crossfade_fade_in
True if we're fading in (recovering from underrun)
Frame structure that stores both data and actual size.
char * data
Pointer to frame data (not owned by this struct)
uint32_t magic
Magic number to detect corruption (FRAME_MAGIC when valid)
size_t size
Actual size of frame data in bytes.
Frame buffer structure for managing video frames.
mutex_t mutex
Mutex for thread-safe access to framebuffer operations.
ringbuffer_t * rb
Underlying ring buffer for frame storage.
Multi-source frame structure for multi-user support.
char * data
Pointer to frame data (not owned by this struct)
uint32_t timestamp
Timestamp when frame was captured.
uint32_t magic
Magic number to detect corruption (FRAME_MAGIC when valid)
uint32_t frame_sequence
Frame sequence number for ordering.
uint32_t source_client_id
Client ID that sent this frame.
size_t size
Actual size of frame data in bytes.
Lock-free ring buffer structure.
bool is_power_of_two
Whether capacity is power of 2 (enables bit masking optimization)
size_t capacity
Number of elements that can be stored.
size_t capacity_mask
Mask for fast modulo when capacity is power of 2.
_Atomic size_t tail
Read position (consumer) - atomic for lock-free operations.
_Atomic size_t size
Current number of elements - atomic for fast size checks.
size_t element_size
Size of each element in bytes.
char * buffer
The actual buffer memory.
_Atomic size_t head
Write position (producer) - atomic for lock-free operations.