ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
video_frame.h
Go to the documentation of this file.
1#pragma once
2
75// C11 stdatomic.h conflicts with MSVC's C++ <atomic> header on Windows.
76#if defined(__cplusplus) && defined(_WIN32)
77#include <atomic>
78#else
79#include <ascii-chat/atomic.h>
80#endif
81#include <stdint.h>
82#include <stdbool.h>
83#include <time.h>
86
87/* ============================================================================
88 * Video Frame Constants
89 * ============================================================================
90 */
91
93#define VIDEO_FRAME_BUFFER_SIZE MAX_FRAME_BUFFER_SIZE
95#define MAX_FRAME_BUFFERS 2
96
97/* ============================================================================
98 * Data Structures
99 * ============================================================================
100 */
101
146
226
247
268
269/* ============================================================================
270 * Video Frame Buffer API
271 * @{
272 */
273
291video_frame_buffer_t *video_frame_buffer_create(const char *client_id);
292
305
324
343
362
367
383
386/* ============================================================================
387 * Simple Frame Swap API (Lightweight Alternative)
388 * @{
389 */
390
407
418
437void simple_frame_swap_update(simple_frame_swap_t *sfs, const void *data, size_t size);
438
453
Platform abstraction layer umbrella header providing unified cross-platform API.
asciichat_error_stats_t stats
⚛️ Atomic operations abstraction layer with debug tracking
Common buffer size definitions.
unsigned int uint32_t
Definition common.h:58
unsigned long long uint64_t
Definition common.h:59
void video_frame_buffer_destroy(video_frame_buffer_t *vfb)
Destroy frame buffer and free all resources.
const video_frame_t * video_frame_peek_latest(video_frame_buffer_t *vfb)
video_frame_t * video_frame_begin_write(video_frame_buffer_t *vfb)
Writer API: Start writing a new frame.
const video_frame_t * simple_frame_swap_get(simple_frame_swap_t *sfs)
Get current frame from simple frame swap.
simple_frame_swap_t * simple_frame_swap_create(void)
Create a simple atomic frame swap.
video_frame_buffer_t * video_frame_buffer_create(const char *client_id)
Create a double-buffered video frame manager.
Definition video_frame.c:17
void video_frame_commit(video_frame_buffer_t *vfb)
Writer API: Commit the frame and swap buffers.
const video_frame_t * video_frame_get_latest(video_frame_buffer_t *vfb)
Reader API: Get latest frame if available.
void video_frame_get_stats(video_frame_buffer_t *vfb, video_frame_stats_t *stats)
Get frame statistics for quality monitoring.
void simple_frame_swap_update(simple_frame_swap_t *sfs, const void *data, size_t size)
Update frame data in simple frame swap.
void simple_frame_swap_destroy(simple_frame_swap_t *sfs)
Destroy simple frame swap and free resources.
ClangTool/LibTooling compatibility shim for stdbool.h.
Atomic value wrapper for integral/boolean types.
Definition atomic.h:76
Mutex type (POSIX: pthread_mutex_t with debug tracking)
Simple atomic frame swap structure.
atomic_t use_frame_a
Atomic flag: true = use frame_a next, false = use frame_b.
video_frame_t frame_b
Second pre-allocated frame.
atomic_t current_frame
Atomic pointer to current frame (stored as uint64_t)
video_frame_t frame_a
First pre-allocated frame.
Video frame buffer manager.
bool active
True if buffer is active (receiving frames)
mutex_t swap_mutex
Brief mutex for pointer swap only.
atomic_t avg_render_time_ns
Average render time in nanoseconds (atomic)
video_frame_t * back_buffer
Currently written frame (writer owns)
atomic_t new_frame_available
Atomic flag: true when new frame available.
atomic_t total_frames_dropped
Total frames dropped (atomic counter)
size_t allocated_buffer_size
Size of allocated data buffers (for cleanup)
video_frame_t * front_buffer
Currently displayed frame (reader owns)
atomic_t avg_decode_time_ns
Average decode time in nanoseconds (atomic)
atomic_t total_frames_received
Total frames received (atomic counter)
atomic_t last_frame_sequence
Last frame sequence number (atomic)
const char * client_id
Client ID (name) this buffer belongs to.
Frame statistics structure.
uint64_t dropped_frames
Total frames dropped (due to buffer full or errors)
uint64_t total_frames
Total frames received since creation.
uint64_t avg_render_time_ns
Average frame render time in nanoseconds.
float drop_rate
Frame drop rate (dropped_frames / total_frames, 0.0-1.0)
uint64_t avg_decode_time_ns
Average frame decode time in nanoseconds.
Video frame structure.
uint64_t sequence_number
Frame sequence number (for drop detection)
uint32_t height
Frame height in pixels.
uint64_t encoding_time_ns
Time taken to encode/decode frame (nanoseconds)
bool is_keyframe
True if this is a keyframe (important frame)
size_t size
Size of frame data in bytes.
uint64_t receive_timestamp_ns
Timestamp when frame was received (nanoseconds)
uint32_t width
Frame width in pixels.
uint64_t capture_timestamp_ns
Timestamp when frame was captured (nanoseconds)
void * data
Frame data pointer (points to pre-allocated buffer)
⏱️ High-precision timing utilities using sokol_time.h and uthash