ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
src/common/session/render.c
Go to the documentation of this file.
1#include <ascii-chat/otel.h>
13
16#include "session/render.h"
17#include "session/capture.h"
18#include "session/display.h"
19#include "session/pipeline.h"
24#include <ascii-chat/common.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include <ascii-chat/log/log.h>
28#include <options/options.h>
33#include <libplatform/keyboard.h>
34#include <libplatform/terminal.h>
35#include <libplatform/compiler.h>
36#include <libplatform/system.h>
37#include <libplatform/terminal.h>
40
41#include <stddef.h>
42#include <stdbool.h>
43#include <stdio.h>
44#include <inttypes.h>
45#ifndef _WIN32
46#include <unistd.h>
47#endif
48
49/* ============================================================================
50 * Unified Render Loop Implementation
51 * ============================================================================ */
52
53// Global flags for snapshot mode timing
55ASCIICHAT_API uint64_t g_snapshot_first_frame_rendered_ns = 0; // Timestamp when first frame was rendered (for terminal output)
56uint64_t g_snapshot_first_capture_ns = 0; // Timestamp when first frame was captured (for video output)
57uint64_t g_snapshot_actual_duration_ms = 0; // Actual elapsed time in ms when capture thread hits snapshot timeout
58uint64_t g_snapshot_last_capture_elapsed_ns = 0; // Elapsed time from first to last frame capture (for PTS distribution)
59
61 session_sleep_for_frame_fn sleep_cb, session_keyboard_handler_fn keyboard_handler, void *user_data) {
62 // Validate required parameters
63 log_debug("capture=%p, display=%p, mode=%s", (void *)capture, (void *)display, capture ? "SYNCHRONOUS" : "EVENT-DRIVEN");
64
65 if (!display) {
66 SET_ERRNO(ERROR_INVALID_PARAM, "display context is NULL");
68 }
69
70 if (!should_exit) {
71 SET_ERRNO(ERROR_INVALID_PARAM, "should_exit callback is NULL");
73 }
74
75 // Validate mode: either capture context OR custom callbacks, not both
76 if (!capture && !capture_cb) {
77 SET_ERRNO(ERROR_INVALID_PARAM, "must provide either capture context or capture callback");
79 }
80
81 if (capture && capture_cb) {
82 SET_ERRNO(ERROR_INVALID_PARAM, "cannot provide both capture context and capture callback");
84 }
85
86 // In event-driven mode, both capture_cb and sleep_cb must be provided together
87 if (capture_cb && !sleep_cb) {
88 SET_ERRNO(ERROR_INVALID_PARAM, "capture_cb requires sleep_cb (must provide both or neither)");
90 }
91
92 if (sleep_cb && !capture_cb) {
93 SET_ERRNO(ERROR_INVALID_PARAM, "sleep_cb requires capture_cb (must provide both or neither)");
95 }
96
97 // SYNCHRONOUS MODE: Use threaded pipeline for capture + render
98 if (capture != NULL) {
99 log_debug("[SESSION_RENDER_LOOP_SYNCHRONOUS] Creating pipeline... (capture=%p, display=%p)", (void *)capture, (void *)display);
100 session_pipeline_t *pipeline = NULL;
101 asciichat_error_t pipeline_err = session_pipeline_create(capture, display, &pipeline);
102 log_debug("[SESSION_RENDER_LOOP_SYNCHRONOUS] pipeline_create returned: %d (pipeline=%p)", pipeline_err, (void *)pipeline);
103 if (pipeline_err != ASCIICHAT_OK) {
104 log_error("[SESSION_RENDER_LOOP_SYNCHRONOUS] Pipeline creation failed %s", asciichat_error_format(NULL, pipeline_err));
105 return pipeline_err;
106 }
107 log_debug("[SESSION_RENDER_LOOP_SYNCHRONOUS] Pipeline created successfully, running main loop...");
108
109 // Disable logging to stdout/stderr during rendering (same as event-driven mode).
110 // This prevents logs from mixing with ASCII art output. Logs still go to file.
112 asciichat_error_t run_err = session_pipeline_run_main(pipeline, should_exit, keyboard_handler, user_data);
114
115 asciichat_error_t drain_err = session_pipeline_destroy(pipeline);
116 // The encoder no longer writes here. Use capture duration, excluding time spent draining.
117 if (GET_OPTION(snapshot_mode) && display && g_snapshot_first_capture_ns > 0)
119
120 return run_err == ASCIICHAT_OK ? drain_err : run_err;
121 } else {
122 log_warn("capture is NULL - will not use pipeline (capture_cb=%p)", (void *)capture_cb);
123 }
124
125 // Snapshot mode state tracking
126 bool snapshot_mode = GET_OPTION(snapshot_mode);
127 bool snapshot_done = false;
128 uint64_t frames_rendered_since_first = 0; // Track frames rendered after first frame (for snapshot delay)
129 // NOTE: g_snapshot_first_frame_rendered is set by display.c when first frame is rendered via platform_write_all()
130
131 log_debug("display=%p capture=%p capture_cb=%p snapshot_mode=%s snapshot_delay=%.2f", (void *)display, (void *)capture, (void *)capture_cb, snapshot_mode ? "YES" : "NO",
132 snapshot_mode ? GET_OPTION(snapshot_delay) : 0.0);
133 if (should_exit(user_data)) {
134 log_warn("EXIT signal already set at entry, aborting render loop");
135 return ASCIICHAT_OK;
136 }
137
138 // Keyboard input initialization (if keyboard handler is provided)
139 // Disable keyboard only in snapshot mode
140 // Keyboard is pre-initialized from asciichat_shared_init()
141 // Allow keyboard input in all other modes if handler provided
142 bool keyboard_enabled = keyboard_handler && !snapshot_mode;
143
144 // Pause mode state tracking (for pause/unpause transitions in event-driven mode)
145 bool initial_paused_frame_rendered = false;
146 bool is_paused = false;
147 log_debug("Keyboard setup - handler=%p snapshot=%s enabled=%s", (void *)keyboard_handler, snapshot_mode ? "YES" : "NO", keyboard_enabled ? "YES" : "NO");
148
149 // Log TTY detection status for debugging keyboard issues
150 log_debug("TTY Status: stdin_tty=%d stdout_tty=%d interactive=%d keyboard_enabled=%d", terminal_is_stdin_tty(), terminal_is_stdout_tty(), terminal_is_interactive(), keyboard_enabled);
151
152 // Frame rate timing (event-driven mode only)
153 uint64_t frame_count = 0;
154 uint64_t frame_start_ns = 0;
155
156 // Event-driven mode: disable console logging during rendering to prevent logs from corrupting frame display
157 // This must be done BEFORE the render loop to avoid repeated lock/unlock cycles that could cause deadlocks
158 log_debug("[EVENT_DRIVEN_MODE] Entering render loop. snapshot_mode=%s", snapshot_mode ? "YES" : "NO");
160
161 asciichat_error_t capture_result = ASCIICHAT_OK;
162 // Main render loop
163 int loop_iteration = 0;
164 log_debug("[RENDER_LOOP_START] snapshot_mode=%s, snapshot_delay=%.2f", snapshot_mode ? "YES" : "NO", snapshot_mode ? GET_OPTION(snapshot_delay) : 0.0);
165
166 // Wait for splash animation to complete before rendering first frame
167 // This prevents ASCII art from mixing with splash screen output
168 // But skip for immediate snapshots (snapshot-delay=0) which need to output first frame immediately
169 static bool splash_wait_done = false;
170 if (!splash_wait_done) {
171 splash_wait_done = true;
172 if (!(GET_OPTION(snapshot_mode) && GET_OPTION(snapshot_delay) == 0.0)) {
173 // Re-enable logging briefly for splash wait, then disable again
177 }
178 }
179
180 // In snapshot mode, we must render at least one frame before checking should_exit
181 // to ensure the snapshot delay timer can start
182 bool force_first_iteration = snapshot_mode && frame_count == 0;
183
184 // Register display context globally so signal handlers (Ctrl+C) can access it
185 // This enables Ctrl+C to close the help screen instead of quitting when help is active
187
188 while (force_first_iteration || (!should_exit(user_data) && !(snapshot_mode && snapshot_done))) {
189 force_first_iteration = false;
190 loop_iteration++;
191 log_debug("[LOOP_ITER] iteration=%d, snapshot_done=%s, frame_count=%lu", loop_iteration, snapshot_done ? "YES" : "NO", frame_count);
192 if (loop_iteration % 60 == 0) {
193 log_debug("iteration %d, should_exit check returning false", loop_iteration);
194 }
195 // Snapshot mode: exit at start of iteration if done
196 // This prevents frame 2+ from being captured when snapshot_delay has elapsed
197 if (snapshot_mode && snapshot_done && frame_count > 0) {
198 log_debug("[SNAPSHOT_EXIT] Snapshot mode: exiting at loop iteration start (snapshot_done=true, frames=%lu)", frame_count);
199 break;
200 }
201
202 log_debug_every(US_PER_SEC_INT, "frame %lu", frame_count);
203 // Frame timing - measure total time to maintain target FPS
204 frame_start_ns = time_get_ns();
205
206 // Frame capture and timing - mode-dependent
207 image_t *image = NULL;
208 uint64_t capture_start_ns = 0;
209 uint64_t capture_end_ns = 0;
210 uint64_t pre_convert_ns = 0;
211 uint64_t post_convert_ns = 0;
212 uint64_t conversion_elapsed_ns = 0;
213
214 // EVENT-DRIVEN MODE: Frames come from callbacks
215 // Both sleep_cb and capture_cb are guaranteed non-NULL by validation above
216 sleep_cb(user_data);
217 ASCII_OTEL_SCOPE(PIPELINE_DISPLAY);
219 image = capture_cb(user_data);
220
221 if (!image) {
223 if (errno_peek_since(frame_scope, &failure)) {
224 capture_result = failure.code;
225 break;
226 }
227 // No frame available - this is normal in async modes (network latency, etc.)
228 // Just continue to next iteration, don't exit
229 continue;
230 }
231
232 // Event-driven mode: increment frame count
233 frame_count++;
234
235 // Convert image to ASCII using display context
236 // Handles all palette, terminal caps, width, height, stretch settings
237 pre_convert_ns = time_get_ns();
238 char *ascii_frame = session_display_convert_to_ascii_reuse(display, image);
239 post_convert_ns = time_get_ns();
240 conversion_elapsed_ns = post_convert_ns - pre_convert_ns;
241
242 if (frame_count <= 3) {
243 log_debug("RENDER_LOOP[%lu]: image=%p, ascii_frame=%p (conversion took %u ms)", frame_count, (void *)image, (void *)ascii_frame, (unsigned)(conversion_elapsed_ns / NS_PER_MS_INT));
244 }
245
246 // Declare variables that need scope beyond the if (ascii_frame) block
247 bool is_paused_frame = initial_paused_frame_rendered && is_paused;
248 bool output_paused_frame = snapshot_mode && is_paused_frame;
249 uint64_t pre_render_ns = 0, post_render_ns = 0;
250
251 if (ascii_frame) {
252 log_debug_every(US_PER_SEC_INT, "ascii_frame ready (len=%zu)", strlen(ascii_frame));
253
254 // Always attempt to render frames; the display context will handle filtering based on:
255 // - TTY mode: render all frames with cursor control (even in snapshot mode, for animation)
256 // - Piped mode: render all frames without cursor control (for continuous capture)
257 // - Snapshot mode on non-TTY: only the display context renders the final frame
258 // BUT: don't render if splash screen is still animating - wait for it to finish
259 bool splash_running = splash_is_running();
260 bool should_write = !splash_running;
261 if (frame_count == 1) {
262 log_dev("[RENDER_FRAME] Frame 1: splash_is_running=%s, should_write=%s", splash_running ? "YES" : "NO", should_write ? "YES" : "NO");
263 }
264 if (should_write) {
265 // is_final = true when: snapshot done, or paused frame (for both snapshot and pause modes)
266 // Profile: render frame
267 pre_render_ns = time_get_ns();
268
269 if (frame_count <= 5 || frame_count % 10 == 0) {
270 log_debug("Frame %lu - calling session_display_render_frame, display=%p", (unsigned long)frame_count, (void *)display);
271 }
272
273 // Check if SIGINT handler cancelled help mode (Ctrl+C while help is open).
274 // The signal handler sets an atomic flag instead of touching state directly.
275 if (display && keyboard_help_check_signal_cancel()) {
276 keyboard_help_toggle(display);
277 log_debug("Ctrl+C cancelled help screen - returning to ASCII art");
278 }
279
280 session_display_render_frame(display, ascii_frame);
281
282 // Snapshot mode: increment frame counter for all displayed frames
283 // Counter starts at 1 for the first displayed frame, then 2, 3, 4... for subsequent frames
284 // Timer is started by display.c when g_snapshot_first_frame_rendered is set
285 if (snapshot_mode && g_snapshot_first_frame_rendered) {
286 frames_rendered_since_first++;
287 log_debug_every(US_PER_SEC_INT, "[SNAPSHOT] Frame rendered: frames_rendered_since_first=%lu", frames_rendered_since_first);
288 }
289 }
290
291 // Keyboard input polling (if enabled) - MUST come before snapshot exit check so help screen can be toggled
292 // Allow keyboard in snapshot mode too (for help screen toggle debugging)
293 // Only enable keyboard if BOTH stdin AND stdout are TTYs to avoid buffering issues
294 // when tcsetattr() modifies the tty line discipline
295 if (keyboard_enabled && keyboard_handler) {
296 uint64_t keyboard_start_ns = time_get_ns();
297 keyboard_key_t key = ui_input_read_key(UI_SCREEN_MEDIA);
298 double keyboard_elapsed_ns = (double)time_elapsed_ns(keyboard_start_ns, time_get_ns());
299 if (keyboard_elapsed_ns >= 0.0) {
300 char _duration_str[TIME_DURATION_BUFFER_SIZE];
301 time_pretty((uint64_t)keyboard_elapsed_ns, -1, _duration_str, sizeof(_duration_str));
302 log_dev_every(1 * NS_PER_SEC_INT, "RENDER[%lu] Keyboard read complete (key=%d) in %s", (unsigned long)frame_count, key, _duration_str);
303 }
304 if (key != KEY_NONE) {
305 log_debug("KEYBOARD: Key pressed: code=%d char='%c'", key, (key >= 32 && key < 127) ? key : '?');
306 // Normal keyboard handler
307 log_debug("KEYBOARD: Normal handler taking key %d", key);
308 keyboard_handler(capture, key, user_data);
309 }
310 }
311
312 // Free frame before checking exit conditions to avoid double-free
313 session_display_release_ascii(display, ascii_frame);
314 }
315
316 // Snapshot mode: check if elapsed time has reached snapshot_delay duration (terminal render timing)
317 // Separate from capture timing - both should measure their own snapshot_delay
318 if (snapshot_mode && !snapshot_done) {
320 double snapshot_delay = GET_OPTION(snapshot_delay);
321 uint64_t now_ns = time_get_ns();
322 uint64_t elapsed_ns = now_ns - g_snapshot_first_frame_rendered_ns;
323 double elapsed_sec = (double)elapsed_ns / (double)NS_PER_SEC_INT;
324
325 if (frames_rendered_since_first == 1 || frames_rendered_since_first % 20 == 0) {
326 log_debug("SNAPSHOT: RENDER_CHECK iter=%lu elapsed=%.3f target=%.2f (from first_frame_rendered)", frames_rendered_since_first, elapsed_sec, snapshot_delay);
327 }
328
329 // snapshot_delay=0 means exit after first frame
330 // snapshot_delay>0 means wait that many seconds before exiting
331 // Exit is based on elapsed wall-clock time, not frame count
332 bool snapshot_should_exit = (snapshot_delay == 0.0) || (elapsed_sec >= snapshot_delay);
333
334 if (snapshot_should_exit) {
335 log_debug("SNAPSHOT: RENDER_DONE at iteration %lu - elapsed=%.3f target=%.2f (setting snapshot_done=true)", frames_rendered_since_first, elapsed_sec, snapshot_delay);
336 // We don't end frames with newlines so the next log would print on the same line as the frame's
337 // last row without an \n here. We only need this \n in stdout when interactive,
338 // so piped snapshots don't have a weird newline in stdout that they don't need.
340 ui_controller_printf(STDOUT_FILENO, "\n");
341 }
342 snapshot_done = true;
343 }
344 } else {
345 if (frames_rendered_since_first == 0) {
346 log_debug("SNAPSHOT: Waiting for first_frame_rendered (g_snapshot_first_frame_rendered=%d, "
347 "g_snapshot_first_frame_rendered_ns=%llu)",
349 }
350 }
351 }
352
353 // Exit conditions: snapshot mode exits after capturing the final frame or initial paused frame
354 if (snapshot_mode && (snapshot_done || output_paused_frame)) {
355 log_debug("SNAPSHOT: EXIT CONDITION MET - snapshot_done=%d, output_paused_frame=%d", snapshot_done, output_paused_frame);
356
357 // Calculate elapsed time from first frame captured (for video file)
358 // This is separate from render time - video should span from first capture to last capture
359 double capture_elapsed_sec = 0.0;
361 uint64_t now_ns = time_get_ns();
362 uint64_t elapsed_ns = now_ns - g_snapshot_first_capture_ns;
363 capture_elapsed_sec = (double)elapsed_ns / (double)NS_PER_SEC_INT;
364 log_debug("SNAPSHOT: EXIT - Capture elapsed: %.3f seconds, render elapsed: %.3f seconds, "
365 "g_snapshot_first_capture_ns=%llu",
366 capture_elapsed_sec, (g_snapshot_first_frame_rendered_ns > 0) ? (double)(now_ns - g_snapshot_first_frame_rendered_ns) / NS_PER_SEC_INT : 0.0,
367 (unsigned long long)g_snapshot_first_capture_ns);
368 } else {
369 log_warn("SNAPSHOT: EXIT condition met but g_snapshot_first_capture_ns is 0!");
370 }
371
372 // Pass actual capture elapsed time to encoder for correct video duration
373 log_debug("SNAPSHOT: About to call session_display_set_snapshot_actual_duration with duration=%.3f, display=%p", capture_elapsed_sec, (void *)display);
374 if (display) {
375 session_display_set_snapshot_actual_duration(display, capture_elapsed_sec);
376 } else {
377 log_warn("SNAPSHOT: display context is NULL!");
378 }
379
380 // Signal application to exit in snapshot mode
382 break;
383 }
384
385 // Frame rendering and timing details (moved down since snapshot exit is now above it)
386 if (ascii_frame) {
387
388 // Measure frame completion right after rendering, BEFORE keyboard polling
389 // This gives us accurate timing for just the core frame operations
390 uint64_t frame_end_render_ns = time_get_ns();
391
392 // Calculate each phase duration
393 uint64_t prestart_ms = (capture_start_ns > frame_start_ns) ? (capture_start_ns - frame_start_ns) / NS_PER_MS_INT : 0;
394 uint64_t capture_ms = (capture_end_ns > capture_start_ns) ? (capture_end_ns - capture_start_ns) / NS_PER_MS_INT : 0;
395 uint64_t convert_ms = conversion_elapsed_ns / NS_PER_MS_INT;
396 uint64_t render_ms = (post_render_ns > pre_render_ns && post_render_ns > 0) ? (post_render_ns - pre_render_ns) / NS_PER_MS_INT : 0;
397 uint64_t total_ms = (frame_end_render_ns > frame_start_ns) ? (frame_end_render_ns - frame_start_ns) / NS_PER_MS_INT : 0;
398
399 // Log phase breakdown every 5 frames
400 if (frame_count % 5 == 0) {
401 log_dev_every(2 * NS_PER_SEC_INT, "PHASE_BREAKDOWN[%lu]: prestart=%llu ms, capture=%llu ms, convert=%llu ms, render=%llu ms (total=%llu ms)", frame_count, prestart_ms, capture_ms, convert_ms,
402 render_ms, total_ms);
403 }
404 } else {
405 // Snapshot mode: even if frame conversion failed, check if we should exit
406 // This ensures snapshot_delay is honored even if display context isn't rendering
407 if (snapshot_mode && snapshot_done) {
408 break;
409 }
410 }
411
412 // In event-driven mode, frame rate limiting is handled by the sleep_cb callback
413 // Synchronous mode (with capture context) uses the pipeline and returns early above
414
415 // Note: Images returned by media sources are cached/reused and should NOT be destroyed
416 // The image pointers are managed by the source and will be cleaned up on source shutdown
417 } // while (!should_exit(user_data)) {
418
419 // Re-enable console logging after rendering completes
421 if (!snapshot_mode && terminal_is_interactive()) {
422 ui_controller_printf(STDOUT_FILENO, "\n");
423 }
424
425 // Keyboard input cleanup (if it was initialized)
426 if (keyboard_enabled) {
429 log_debug_every(2 * NS_PER_SEC_INT, "Keyboard input disabled");
430 }
431
432 // Unregister global display context (for signal handlers)
434
435 return capture_result;
436}
Application-level callbacks for library code.
#define APP_CALLBACK_VOID(callback_name)
bool errno_peek_since(asciichat_errno_scope_t scope, asciichat_error_context_t *out)
asciichat_errno_scope_t errno_checkpoint(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,...)
📹 Unified media capture abstraction for session-based video sources
🎞️ FFmpeg-based media decoder for video and audio streams
unsigned long long uint64_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
#define log_dev(...)
Log a DEV message (most verbose, development only).
Definition log/log.h:551
#define log_error(...)
Log an ERROR message.
Definition log/log.h:604
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:565
void log_set_terminal_output(bool enabled)
Control stderr output to terminal.
Definition log/log.c:818
#define NS_PER_SEC_INT
Definition time.h:173
int time_pretty(uint64_t nanoseconds, int decimals, char *buffer, size_t buffer_size)
Format nanoseconds as a compact duration with configurable sub-minute precision.
Definition time.c:406
#define TIME_DURATION_BUFFER_SIZE
Definition time.h:40
#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_SEC_INT
Definition time.h:177
#define GET_OPTION(field)
Definition options.h:1339
#define ASCIICHAT_API
Export symbols on Unix platforms (Linux, macOS).
Definition api.h:87
void keyboard_help_toggle(session_display_ctx_t *ctx)
Toggle keyboard help on/off.
bool(* session_should_exit_fn)(void *user_data)
Exit condition callback type.
void(* session_keyboard_handler_fn)(session_capture_ctx_t *capture, int key, void *user_data)
Keyboard input handler callback type.
bool splash_is_running(void)
Check if splash screen animation is currently running.
Definition splash.c:485
void(* session_sleep_for_frame_fn)(void *user_data)
Sleep callback for custom frame timing.
struct session_display_ctx session_display_ctx_t
session display config is intentionally a small, concrete record. Fields such as snapshot_mode,...
image_t *(* session_capture_fn)(void *user_data)
Capture callback for event-driven frame source.
void session_display_set_snapshot_actual_duration(session_display_ctx_t *ctx, double actual_duration_sec)
Set the actual wall-clock duration for snapshot mode frame timing.
asciichat_error_t session_render_loop(session_capture_ctx_t *capture, session_display_ctx_t *display, session_should_exit_fn should_exit, session_capture_fn capture_cb, session_sleep_for_frame_fn sleep_cb, session_keyboard_handler_fn keyboard_handler, void *user_data)
Unified render loop for all display modes.
struct session_capture_ctx session_capture_ctx_t
session capture config keeps the values that move through the subsystem: type, path,...
void session_display_render_frame(session_display_ctx_t *ctx, const char *frame_data)
Render an ASCII frame to the terminal.
void session_display_set_global_context(session_display_ctx_t *ctx)
Set the global display context (for signal handlers like Ctrl+C).
bool keyboard_help_check_signal_cancel(void)
Check if help screen closure was requested by signal handler.
void splash_wait_for_animation(void)
Wait for splash animation thread to fully exit.
Definition splash.c:491
🔊 Audio Capture and Playback Interface for ascii-chat
⚙️ Common definitions, error codes, macros, and types shared throughout the application
🆘 Interactive keyboard help overlay for session keyboard shortcuts
📝 Logging API with multiple log levels and terminal output control
#define log_debug_every(interval_us, fmt,...)
Rate-limited DEBUG logging.
Definition log/log.h:719
#define log_dev_every(interval_us, fmt,...)
Rate-limited DEV logging.
Definition log/log.h:716
void signal_exit(void)
Definition main.c:262
bool should_exit(void)
Definition main.c:260
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
#define ASCII_OTEL_SCOPE(id)
Definition otel.h:102
asciichat_error_t session_pipeline_run_main(session_pipeline_t *pipeline, session_should_exit_fn should_exit, session_keyboard_handler_fn keyboard_handler, void *user_data)
Definition pipeline.c:628
asciichat_error_t session_pipeline_create(session_capture_ctx_t *capture, session_display_ctx_t *display, session_pipeline_t **out)
Definition pipeline.c:536
bool g_snapshot_first_frame_rendered
asciichat_error_t session_pipeline_destroy(session_pipeline_t *pipeline)
Definition pipeline.c:777
Three-thread render pipeline: capture → display/encode.
struct session_pipeline_s session_pipeline_t
Definition pipeline.h:22
Read ANSI ASCII frames from file descriptor, chunked by height.
Interactive search filtering for terminal screens.
🎬 Unified media source abstraction for webcam, files, and stdin
Intro and status screen display for ascii-chat with animated rainbow effects.
void session_display_release_ascii(session_display_ctx_t *ctx, char *ascii)
char * session_display_convert_to_ascii_reuse(session_display_ctx_t *ctx, const image_t *image)
🖥️ Unified terminal display abstraction for session-based rendering
uint64_t g_snapshot_last_capture_elapsed_ns
uint64_t g_snapshot_first_frame_rendered_ns
uint64_t g_snapshot_first_capture_ns
uint64_t g_snapshot_actual_duration_ms
Centralized render loop abstraction for all display modes.
bool terminal_is_interactive(void)
bool terminal_is_stdin_tty(void)
bool terminal_is_stdout_tty(void)
When code needs to work with asciichat errno snapshot, it keeps total, copied here instead of scatter...
SIMD-friendly storage for one RGB pixel. r, g, and b hold the color channels and padding keeps the la...
⏱️ High-precision timing utilities using sokol_time.h and uthash
void ui_controller_remove(ui_screen_t screen)
asciichat_error_t ui_controller_printf(int fd, const char *format,...)
@ UI_SCREEN_MEDIA
@ UI_SCREEN_HELP
keyboard_key_t ui_input_read_key(ui_screen_t screen)
Definition tui/input.c:374