ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
client/capture.c
Go to the documentation of this file.
1
2/* Storage capacities in elements; text buffers include the terminating NUL. */
3#define CLIENT_CAPTURE_WEBCAM_INDEX_BUFFER_SIZE 32
4
7#include <ascii-chat/otel.h>
101#include "../main.h" // Global exit API
102#include "audio.h"
103#include "main.h"
104#include "server.h"
105#include "session/capture.h"
107#include <ascii-chat/common.h>
113#include <ascii-chat/util/fps.h>
114#include <ascii-chat/util/thread.h> // For THREAD_IS_CREATED macro
115#include <ascii-chat/util/time.h>
117#include <libplatform/atomic.h>
118#include <libplatform/compiler.h>
119#include <libplatform/system.h>
120#include <libplatform/terminal.h>
121#include <options/options.h>
122#include <options/rcu.h> // For RCU-based options access
123#include <string.h>
124#include <time.h>
125
126/* ============================================================================
127 * Session Capture Context
128 * ============================================================================
129 */
130
140static session_capture_ctx_t *g_capture_capture_ctx = NULL;
141
142/* ============================================================================
143 * Capture Thread Management
144 * ============================================================================
145 */
146
147/* ============================================================================
148 * Frame Processing Constants
149 * ============================================================================
150 */
152/* Keep the implicit network cadence below the synchronization inspector's
153 * per-second lock budget. Users can still request a higher rate explicitly
154 * with --fps; the negotiated peer rate remains authoritative once connected. */
155#define CAPTURE_TARGET_FPS 6
156
157/* Frame processing now handled by session library via
158 * session_capture_process_for_transmission() */
159/* ============================================================================
160 * Capture Thread Implementation
161 * ============================================================================
162 */
163
191static void *webcam_capture_thread_func(void *arg) {
192 client_connection_t *connection = arg;
193
194 // FPS tracking for webcam capture thread
195 fps_t fps_tracker = {0};
196 bool fps_tracker_initialized = false;
197 uint64_t capture_frame_count = 0;
198 uint64_t last_capture_frame_time_ns = 0;
199 image_t *transmission_frame =
200 NULL; // Capture worker owns reusable network pixels.
201 image_t *last_frame = NULL; // Borrows transmission_frame for paused playback.
202 const char *video_codec = GET_OPTION(video_codec);
203 bool automatic_codec = strcmp(video_codec, "auto") == 0;
204 video_codec_t selected_codec =
205 strcmp(video_codec, "raw") == 0 ? VIDEO_CODEC_RGBA
206 : strcmp(video_codec, "h264") == 0 ? VIDEO_CODEC_H264
208 if (automatic_codec) {
209 while (selected_codec != VIDEO_CODEC_RGBA &&
210 !video_encoder_is_available(selected_codec))
211 selected_codec = selected_codec == VIDEO_CODEC_H265 ? VIDEO_CODEC_H264
213 }
214 // Each connection starts at the requested codec with a fresh bitstream.
216 connection->video_encoder = NULL;
217 if (!fps_tracker_initialized) {
218 int target_fps =
220 fps_init(&fps_tracker, target_fps, "WEBCAM_TX");
221 fps_tracker_initialized = true;
222 }
223
224 while (!should_exit() && !server_connection_is_lost(connection)) {
225 // Check connection status
226 if (!server_connection_is_active(connection)) {
229 "Capture thread: waiting for connection to become active");
230 platform_sleep_us(100 * US_PER_MS_INT); // Wait for connection
231 continue;
232 }
233
234 // Frame rate limiting using session capture adaptive sleep
236
237 // Re-check connection after FPS sleep in case it was lost during sleep
238 // (reconnection)
239 if (!server_connection_is_active(connection) ||
240 server_connection_is_lost(connection)) {
241 log_debug("Capture thread: connection lost after FPS sleep, exiting");
242 break;
243 }
244
245 ASCII_OTEL_SCOPE(CLIENT_VIDEO_FRAME);
246 // Read frame using session capture library
249 asciichat_error_context_t capture_failure;
250 if (!image && errno_peek_since(frame_scope, &capture_failure)) {
251 errno_request_exit(capture_failure.code);
252 signal_exit();
253 break;
254 }
255
256 // Check if media is paused and we have a last frame - render last frame to
257 // keep keyboard polling active
258 if (!image) {
261 connection->capture_context);
263 media_source_is_paused(source) && last_frame) {
264 // Use last frame when paused (keeps display thread rendering and
265 // keyboard polling active)
266 image = last_frame;
267 log_debug_every(LOG_RATE_SLOW, "Using cached frame while paused");
268 } else if (session_capture_at_end(connection->capture_context)) {
269 // Check if we've reached end of file for media sources
270 log_debug("Media source reached end of file");
271 last_frame = NULL;
272 break; // Exit capture loop - end of media
273 } else {
276 "No frame available from media source yet (returned NULL)");
277 platform_sleep_us(10 * US_PER_MS_INT); // 10ms delay before retry
278 continue;
279 }
280 }
281
282 // Track frame for FPS reporting
283 fps_frame_ns(&fps_tracker, time_get_ns(), "webcam frame captured");
284
285 // Copy/resize into capture-owned storage; the media source retains its
286 // input.
288 connection->capture_context, image, &transmission_frame) !=
290 continue;
291 image_t *processed_image = transmission_frame;
292
293 // Check connection before sending
294 if (!server_connection_is_active(connection)) {
295 log_warn("Connection lost before sending, stopping video transmission");
296 break;
297 }
298
299 // Send frame packet to server using proper packet format
300 acip_transport_t *transport = server_connection_get_transport(connection);
301 if (!transport || !server_connection_is_active(connection)) {
302 log_warn(
303 "Transport became unavailable during capture, stopping transmission");
304 break;
305 }
306
307 uint64_t send_start_ns = time_get_ns();
308
310 asciichat_error_t send_result;
311 bool encoding_failed = false;
312 for (;;) {
313 if (selected_codec == VIDEO_CODEC_RGBA) {
314 send_result = threaded_send_image_frame(
315 connection, processed_image->pixels, (uint32_t)processed_image->w,
316 (uint32_t)processed_image->h, 1);
317 break;
318 }
321 connection, processed_image->pixels, (uint32_t)processed_image->w,
322 (uint32_t)processed_image->h, selected_codec, &encoding_failed);
323 if (!encoding_failed || !automatic_codec || send_result == ERROR_MEMORY) {
324 if (send_result == ASCIICHAT_OK)
326 break;
327 }
328 log_warn("%s encoding failed; automatic video is switching to %s",
329 selected_codec == VIDEO_CODEC_H265 ? "HEVC" : "H.264",
330 selected_codec == VIDEO_CODEC_H265 ? "H.264" : "raw");
333 connection->video_encoder = NULL;
334 selected_codec = selected_codec == VIDEO_CODEC_H265 ? VIDEO_CODEC_H264
336 encoding_failed = false;
337 }
338 if (send_result == ASCIICHAT_OK)
340 connection->capture_context,
342 const char *codec_name = selected_codec == VIDEO_CODEC_H265 ? "H265"
343 : selected_codec == VIDEO_CODEC_H264 ? "H264"
344 : "RAW";
345 if (encoding_failed) {
346 log_error("%s video encoding failed (%s). Use --video-codec auto for "
347 "fallback or --video-codec raw.",
348 codec_name, asciichat_error_format(NULL, send_result));
349 errno_request_exit(send_result);
350 signal_exit();
351 break;
352 }
353
354 // If send failed due to connection loss, break out of loop
355 if (send_result != ASCIICHAT_OK &&
356 !server_connection_is_active(connection)) {
357 log_debug("Connection lost during send, stopping transmission");
358 break;
359 }
360 uint64_t send_duration_ns = time_elapsed_ns(send_start_ns, time_get_ns());
361
362 if (send_result != ASCIICHAT_OK &&
364 LOG_ERRNO_IF_SET("Dropping locally rejected video frame");
366 continue;
367 }
368 if (send_result != ASCIICHAT_OK) {
369 log_error("🔴 CAPTURE_SEND_FAILED: IMAGE_FRAME_%s send failed %s after "
370 "%.1fms, closing connection",
371 codec_name, asciichat_error_format(NULL, send_result),
372 (double)send_duration_ns / 1e6);
373 server_connection_lost(connection);
374 break;
375 }
376
377 ASSERT_NO_ERRNO_SINCE(send_scope);
379 if (send_duration_ns > 500 * NS_PER_MS_INT) {
380 log_warn("⚠️ SLOW_FRAME_SEND: %.1fms to send %ux%u %s frame (may "
381 "indicate full send buffer)",
382 (double)send_duration_ns / 1e6, processed_image->w,
383 processed_image->h, codec_name);
384 }
385
388 "CAPTURE_FRAME_SENT: IMAGE_FRAME_%s delivered to server in %.1fms",
389 codec_name, (double)send_duration_ns / 1e6);
390
391 // Keep the processed workspace itself for pause; no second image copy.
392 last_frame = processed_image;
393
394 // FPS tracking - frame successfully captured and sent
395 capture_frame_count++;
396
397 // Calculate time since last frame for lag detection (using nanosecond
398 // precision internally)
399 uint64_t frame_capture_time_ns = time_get_ns();
400
401 uint64_t frame_interval_ns =
402 time_elapsed_ns(last_capture_frame_time_ns, frame_capture_time_ns);
403 last_capture_frame_time_ns = frame_capture_time_ns;
404
405 // Expected frame interval in nanoseconds
406 uint64_t expected_interval_ns =
409 uint64_t lag_threshold_ns =
410 expected_interval_ns + (expected_interval_ns / 2); // 50% over expected
411
412 // Log warning if frame took too long to capture (display in milliseconds
413 // for readability)
414 if (capture_frame_count > 1 && frame_interval_ns > lag_threshold_ns) {
415 double late_ms = (double)(frame_interval_ns - expected_interval_ns) / 1e6;
416 double expected_ms = (double)expected_interval_ns / 1e6;
417 double actual_ms = (double)frame_interval_ns / 1e6;
418 double actual_fps = 1e9 / (double)frame_interval_ns;
420 "CLIENT CAPTURE LAG: Frame captured %.1fms late (expected "
421 "%.1fms, got %.1fms, actual fps: %.1f)",
422 late_ms, expected_ms, actual_ms, actual_fps);
423 }
424
425 // Yield to reduce CPU usage
426 platform_sleep_us(1 * US_PER_MS_INT); // 1ms
427 }
428
429#ifdef DEBUG_THREADS
430 log_debug("Webcam capture thread stopped");
431#endif
432
433 image_destroy(transmission_frame);
434 transmission_frame = NULL;
435 last_frame = NULL;
436
437 log_debug("CAPTURE_THREAD_EXIT: About to mark thread as exited");
438 atomic_store_bool(&connection->capture_thread_exited, true);
439 log_debug("CAPTURE_THREAD_EXIT: Thread marked as exited, cleaning up errno");
440
441 // Clean up thread-local error context before exit
442
443 log_debug("CAPTURE_THREAD_EXIT: Exiting capture thread");
444 return NULL;
445}
446/* ============================================================================
447 * Public Interface Functions
448 * ============================================================================
449 */
461 // Build capture configuration from options
462 session_capture_config_t config = {0};
463 const char *media_url = GET_OPTION(media_url);
464 const char *media_file = GET_OPTION(media_file);
465 bool media_from_stdin = GET_OPTION(media_from_stdin);
466
467 if (media_url && media_url[0] != '\0') {
468 // Network URL streaming (takes priority over --file)
469 // Don't open webcam when streaming from URL
470 config.type = MEDIA_SOURCE_FILE;
471 config.path = media_url;
472 config.loop = false; // Network URLs cannot be looped
473 log_debug("Using network URL: %s (webcam disabled)", media_url);
474 } else if (media_file && media_file[0] != '\0') {
475 // File or stdin streaming - don't open webcam
476 config.type = media_from_stdin ? MEDIA_SOURCE_STDIN : MEDIA_SOURCE_FILE;
477 config.path = media_file;
478 config.loop = GET_OPTION(media_loop) && !media_from_stdin;
479 log_debug("Using media %s: %s (webcam disabled)",
480 media_from_stdin ? "stdin" : "file", media_file);
481 } else if (GET_OPTION(test_pattern)) {
482 // Test pattern mode - don't open real webcam
483 config.type = MEDIA_SOURCE_TEST;
484 config.path = NULL;
485 log_debug("Using test pattern mode");
486 } else {
487 // Webcam mode (default)
488 static char webcam_index_str[CLIENT_CAPTURE_WEBCAM_INDEX_BUFFER_SIZE];
489 safe_snprintf(webcam_index_str, sizeof(webcam_index_str), "%u",
490 GET_OPTION(webcam_index));
491 config.type = MEDIA_SOURCE_WEBCAM;
492 config.path = webcam_index_str;
493 log_debug("Using webcam device %u", GET_OPTION(webcam_index));
494 }
495 int configured_fps = GET_OPTION(fps);
496 config.target_fps =
497 configured_fps > 0 ? (uint32_t)configured_fps : CAPTURE_TARGET_FPS;
498 config.resize_for_network =
499 true; // Client always resizes for network transmission
500
501 // Configure audio capture with fallback to microphone
502 config.enable_audio = true;
503 config.audio_fallback_to_mic = true;
505
506 // Add seek timestamp if specified
507 config.initial_seek_timestamp = GET_OPTION(media_seek_timestamp);
508
509 // Create capture context using session library
511 g_capture_capture_ctx = session_capture_create(&config);
512 if (!g_capture_capture_ctx) {
513 // Check if there's already an error set (e.g., ERROR_WEBCAM_IN_USE)
515 asciichat_error_t existing_error =
516 errno_peek_since(create_scope, &failure) ? failure.code : ASCIICHAT_OK;
517 log_debug("session_capture_create failed %s",
518 asciichat_error_format(NULL, existing_error));
519 if (existing_error != ASCIICHAT_OK) {
520 log_debug("Returning existing error %s",
521 asciichat_error_format(NULL, existing_error));
522 return existing_error;
523 }
524 SET_ERRNO(ERROR_MEDIA_INIT, "Failed to initialize capture source");
525 return -1;
526 }
527
528 return 0;
529}
530
541 if (!connection->capture_context)
542 return 0;
543 if (THREAD_IS_CREATED(connection->capture_thread_created)) {
544 log_warn("Capture thread already created");
545 return 0;
546 }
547
548 // Start webcam capture thread
549 atomic_store_bool(&connection->capture_thread_exited, false);
551 webcam_capture_thread_func, connection, 2,
552 "webcam_capture") != ASCIICHAT_OK) {
553 SET_ERRNO(ERROR_THREAD, "Webcam capture thread creation failed");
554 LOG_ERRNO_IF_SET("Webcam capture thread creation failed");
555 return -1;
556 }
557
558 connection->capture_thread_created = true;
559 log_debug("Webcam capture thread created successfully");
560
561 return 0;
562}
563
572 if (!connection)
573 return;
574 if (!THREAD_IS_CREATED(connection->capture_thread_created)) {
575 return;
576 }
577
578 // Wait for thread to exit gracefully
579 int wait_count = 0;
580 while (wait_count < 20 &&
582 platform_sleep_us(100 * US_PER_MS_INT); // 100ms
583 wait_count++;
584 }
585
586 if (!atomic_load_bool(&connection->capture_thread_exited)) {
587 log_warn("Capture thread not responding after 2 seconds - will be joined "
588 "by thread pool");
589 }
590
591 // Thread will be joined by thread_pool_stop_all() in client_connection_stop()
592 connection->capture_thread_created = false;
593}
594
602 return atomic_load_bool(&connection->capture_thread_exited);
603}
604
613
614 // Destroy capture context
615 if (g_capture_capture_ctx) {
616 session_capture_destroy(g_capture_capture_ctx);
617 g_capture_capture_ctx = NULL;
618 }
619}
620
622 return session_capture_get_media_source(g_capture_capture_ctx);
623}
624
626 return g_capture_capture_ctx;
627}
void errno_request_exit(asciichat_error_t code)
bool errno_peek_since(asciichat_errno_scope_t scope, asciichat_error_context_t *out)
void errno_scope_end(asciichat_errno_scope_t scope, asciichat_errno_outcome_t outcome)
asciichat_errno_scope_t errno_checkpoint(void)
asciichat_errno_scope_t errno_scope_begin(void)
const char * asciichat_error_format(const char *message, asciichat_error_t code)
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
#define ASSERT_NO_ERRNO_SINCE(scope)
@ ASCIICHAT_ERRNO_HANDLED
@ ASCIICHAT_ERRNO_DISMISSED
#define LOG_ERRNO_IF_SET(message)
void atomic_store_bool(atomic_t *a, bool value)
Atomically store a boolean value.
bool atomic_load_bool(atomic_t *a)
Atomic pointer wrapper.
void capture_stop_thread(client_connection_t *connection)
Stop capture thread.
bool capture_thread_exited(client_connection_t *connection)
Check if capture thread has exited.
#define CAPTURE_TARGET_FPS
int capture_init()
Initialize capture subsystem.
#define CLIENT_CAPTURE_WEBCAM_INDEX_BUFFER_SIZE
void * capture_get_media_source(void)
void capture_cleanup()
Cleanup capture subsystem.
int capture_start_thread(client_connection_t *connection)
Start capture thread.
session_capture_ctx_t * capture_get_context(void)
ascii-chat Client Mode Entry Point Header
video_codec_t
Definition codecs.h:28
@ VIDEO_CODEC_RGBA
Raw RGBA (4 bytes per pixel, uncompressed).
Definition codecs.h:29
@ VIDEO_CODEC_H264
H.264 (AVC) video codec.
Definition codecs.h:32
@ VIDEO_CODEC_H265
H.265 (HEVC) video codec.
Definition codecs.h:30
void session_capture_complete_open(session_capture_ctx_t *ctx, uint64_t epoch)
uint64_t session_capture_source_epoch(session_capture_ctx_t *ctx)
asciichat_error_t session_capture_process_for_transmission_into(session_capture_ctx_t *ctx, image_t *frame, image_t **output)
📹 Unified media capture abstraction for session-based video sources
Named object registry for debugging — log identifiable resource names.
bool video_encoder_is_available(video_codec_t codec)
Definition encoder.c:53
void h265_encoder_destroy(h265_encoder_t *encoder)
Definition encoder.c:178
audio_visualization_source_t source
Definition fft.c:25
⏱️ FPS tracking utility for monitoring frame throughput across all threads
unsigned int uint32_t
void fps_frame_ns(fps_t *tracker, uint64_t current_time_ns, const char *context)
Track a frame and detect lag conditions (nanosecond version - PRIMARY).
Definition fps.c:58
unsigned long long uint64_t
void fps_init(fps_t *tracker, int expected_fps, const char *name)
Initialize FPS tracker.
Definition fps.c:37
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_MEMORY
Definition error_codes.h:55
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_MEDIA_INIT
Definition error_codes.h:70
@ ERROR_THREAD
#define LOG_RATE_FAST
Log rate limit: 1 second (1,000,000 microseconds).
Definition log_rates.h:31
#define LOG_RATE_SLOW
Log rate limit: 10 seconds (10,000,000 microseconds).
Definition log_rates.h:41
#define LOG_RATE_NORMAL
Log rate limit: 3 seconds (3,000,000 microseconds).
Definition log_rates.h:34
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
#define log_error(...)
Log an ERROR message.
Definition log/log.h:604
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:565
bool media_source_is_paused(media_source_t *source)
Check if media source is paused.
Definition source.c:1190
media_source_type_t media_source_get_type(media_source_t *source)
Get media source type.
Definition source.c:1099
@ MEDIA_SOURCE_STDIN
Piped or redirected input.
Definition source.h:105
@ MEDIA_SOURCE_WEBCAM
Hardware webcam device.
Definition source.h:103
@ MEDIA_SOURCE_FILE
Media file (video/audio).
Definition source.h:104
@ MEDIA_SOURCE_TEST
Test pattern generator.
Definition source.h:106
#define NS_PER_SEC_INT
Definition time.h:173
#define NS_PER_MS_INT
Definition time.h:172
uint64_t time_elapsed_ns(uint64_t start_ns, uint64_t end_ns)
Calculate elapsed time with wraparound safety.
Definition time.c:126
#define US_PER_MS_INT
Definition time.h:176
#define GET_OPTION(field)
Definition options.h:1339
bool session_capture_at_end(session_capture_ctx_t *ctx)
Check if capture source has reached end of stream.
struct session_capture_ctx session_capture_ctx_t
session capture config keeps the values that move through the subsystem: type, path,...
image_t * session_capture_read_frame(session_capture_ctx_t *ctx)
Read the next video frame from the capture source.
uint32_t session_capture_get_target_fps(session_capture_ctx_t *ctx)
Get the target FPS configured for this capture context.
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:508
session_capture_ctx_t * session_capture_create(const session_capture_config_t *config)
Legacy function - creates either mirror or network capture based on options.
void * session_capture_get_media_source(session_capture_ctx_t *ctx)
Get the underlying media source from capture context.
void session_capture_sleep_for_fps(session_capture_ctx_t *ctx)
Sleep to maintain target frame rate.
void session_capture_destroy(session_capture_ctx_t *ctx)
Destroy session capture context and free resources.
void image_destroy(image_t *image)
Destroy an image allocated with image_new().
⚙️ Common definitions, error codes, macros, and types shared throughout the application
ACIP client-side protocol API.
Network error handling utilities.
bool network_error_is_local_rejection(asciichat_error_t code)
#define log_debug_every(interval_us, fmt,...)
Rate-limited DEBUG logging.
Definition log/log.h:719
#define log_warn_every(interval_us, fmt,...)
Rate-limited WARN logging.
Definition log/log.h:725
void signal_exit(void)
Definition main.c:262
bool should_exit(void)
Definition main.c:260
Global application exit and signal handling API.
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
#define ASCII_OTEL_SCOPE(id)
Definition otel.h:102
ACIP shared/bidirectional packet sending functions.
🎬 Unified media source abstraction for webcam, files, and stdin
audio_context_t * audio_get_context(void)
Get the global audio context for use by other subsystems.
ascii-chat Client Audio Processing Management Interface
struct client_connection client_connection_t
asciichat_error_t threaded_send_image_frame_encoded(client_connection_t *connection, const void *pixel_data, uint32_t width, uint32_t height, video_codec_t codec, bool *encoding_failed)
Send H.265-encoded video frame to server (thread-safe).
bool server_connection_is_active(client_connection_t *connection)
Establish connection to ascii-chat server.
void server_connection_lost(client_connection_t *connection)
Signal that connection has been lost.
bool server_connection_is_lost(client_connection_t *connection)
Check if connection loss has been detected.
acip_transport_t * server_connection_get_transport(client_connection_t *connection)
Get ACIP transport instance.
asciichat_error_t threaded_send_image_frame(client_connection_t *connection, const void *pixel_data, uint32_t width, uint32_t height, uint32_t pixel_format)
Thread-safe image frame transmission.
ascii-chat Client Server Connection Management Interface
🔤 String Manipulation and Shell Escaping Utilities
When code needs to work with asciichat errno snapshot, it keeps total, copied here instead of scatter...
thread_pool_t * client_worker_pool
session_capture_ctx_t * capture_context
h265_encoder_t *volatile video_encoder
Counters and timestamps used to calculate and report frame rate.
Definition fps.h:59
SIMD-friendly storage for one RGB pixel. r, g, and b hold the color channels and padding keeps the la...
int h
Image height in pixels (must be > 0).
rgb_pixel_t * pixels
Pixel data array (width * height RGB pixels, row-major order).
int w
Image width in pixels (must be > 0).
Media source for video and audio capture.
Definition source.c:48
Media-source and loader settings used to create a session capture context.
media_source_type_t type
Media source type (WEBCAM, FILE, STDIN, TEST).
const char * path
Device index (for webcam) or file path (for file sources).
uint32_t target_fps
Target frame rate in FPS (e.g., 60 for display, 144 for network).
double initial_seek_timestamp
Seek to this timestamp after opening media (0.0 = no seek).
bool audio_fallback_to_mic
Fall back to microphone if file audio is not available.
bool resize_for_network
Resize frames to network-optimal dimensions (MAX_FRAME_WIDTH x MAX_FRAME_HEIGHT).
bool loop
Enable loop playback for file sources.
bool enable_audio
Enable audio capture from media source.
void * mic_audio_ctx
Microphone audio context for fallback (borrowed, not owned).
test pattern is intentionally a small, concrete record. Fields such as image, rgba give callers the i...
🧵 Thread lifecycle management helpers
#define THREAD_IS_CREATED(created_flag)
Definition thread.h:66
asciichat_error_t thread_pool_spawn(thread_pool_t *pool, void *(*thread_func)(void *), void *thread_arg, int stop_id, const char *thread_name)
Spawn a worker thread in the pool.
🧵 Generic thread pool abstraction for managing worker threads
⏱️ High-precision timing utilities using sokol_time.h and uthash