ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
video_frame.h
Go to the documentation of this file.
1#pragma once
2#include <libplatform/mutex.h>
3
75
76// C11 stdatomic.h conflicts with MSVC's C++ <atomic> header on Windows.
77#if defined(__cplusplus) && defined(_WIN32)
78#include <atomic>
79#else
80#include <libplatform/atomic.h>
81#endif
82#include <stdint.h>
83#include <stdbool.h>
84#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
147
231
252
274
275/* ============================================================================
276 * Video Frame Buffer API
277 * @{
278 */
279
297video_frame_buffer_t *video_frame_buffer_create(const char *client_id);
298
311
330
349
368
373
389
391
392/* ============================================================================
393 * Simple Frame Swap API (Lightweight Alternative)
394 * @{
395 */
396
413
424
443void simple_frame_swap_update(simple_frame_swap_t *sfs, const void *data, size_t size);
444
459
Common buffer size definitions.
unsigned int uint32_t
Definition common.h:62
unsigned long long uint64_t
Definition common.h:63
void video_frame_buffer_destroy(video_frame_buffer_t *vfb)
Destroy frame buffer and free all resources.
Definition video_frame.c:98
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:19
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.
Counters and timing measurements used to monitor frame delivery and quality.
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.
One captured, decoded, or rendered video frame and its timing metadata.
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).
video_frame_t frames[2]
Pre-allocated frame structures (reused forever).
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.
Counters and timing measurements used to monitor frame delivery and quality.
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.
When code needs to work with simple frame swap, it keeps current_frame, frame_a, frame_b,...
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