ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
display.h File Reference

🖥️ Unified terminal display abstraction for session-based rendering More...

Go to the source code of this file.

Data Structures

struct  session_display_config_t
 Configuration for session display context. More...
 

Typedefs

typedef bool(* session_display_should_exit_fn) (void *user_data)
 Callback type to check if initialization should be cancelled.
 
typedef struct session_display_ctx session_display_ctx_t
 Opaque session display context handle.
 

Functions

session_display_ctx_t * session_display_create (const session_display_config_t *config)
 Create a new session display context.
 
session_display_ctx_t * session_display_get_global_context (void)
 Get the global display context (used for signal handlers and special cleanup)
 
void session_display_set_global_context_public (session_display_ctx_t *ctx)
 Set the global display context (public setter for discovery cleanup)
 
void session_display_destroy (session_display_ctx_t *ctx)
 Destroy session display context and free resources.
 
void session_display_set_stdin_reader (session_display_ctx_t *ctx, void *reader)
 Set stdin frame reader for ASCII-to-video rendering.
 
bool session_display_has_tty (session_display_ctx_t *ctx)
 Check if display has a TTY (terminal) available.
 
const terminal_capabilities_t * session_display_get_caps (session_display_ctx_t *ctx)
 Get detected terminal capabilities.
 
const char * session_display_get_palette_chars (session_display_ctx_t *ctx)
 Get the palette characters string.
 
size_t session_display_get_palette_len (session_display_ctx_t *ctx)
 Get the palette character count.
 
const char * session_display_get_luminance_palette (session_display_ctx_t *ctx)
 Get the luminance mapping palette.
 
int session_display_get_tty_fd (session_display_ctx_t *ctx)
 Get the TTY file descriptor.
 
void * session_display_get_stdin_reader (session_display_ctx_t *ctx)
 Get the stdin frame reader for ASCII-to-video rendering.
 
bool session_display_has_render_file (session_display_ctx_t *ctx)
 Check if display has render-file configured.
 
uint32_t session_display_get_render_fps (session_display_ctx_t *ctx)
 Get the render FPS configured for file output.
 
asciichat_error_t session_display_init_render_file (session_display_ctx_t *ctx, uint32_t fps)
 Initialize render-file output after the capture frame rate is known.
 
void session_display_set_render_live_timing (session_display_ctx_t *ctx)
 
void session_display_set_render_fps (session_display_ctx_t *ctx, uint32_t fps)
 Set the render FPS for file output encoding.
 
bool session_display_has_first_frame (session_display_ctx_t *ctx)
 Check if the display has rendered its first frame.
 
void session_display_reset_first_frame (session_display_ctx_t *ctx)
 Reset the first frame flag to allow splash screen to show again on next render.
 
char * session_display_convert_to_ascii (session_display_ctx_t *ctx, const image_t *image)
 Convert an image to ASCII art using display context and command-line options.
 
void session_display_write_ascii (session_display_ctx_t *ctx, const char *frame_data)
 Write ASCII frame to terminal only (no encoding)
 
void session_display_encode_frame (session_display_ctx_t *ctx, const image_t *image, uint64_t captured_ns)
 Encode frame to render-file (FFmpeg only, no terminal output)
 
void session_display_render_frame (session_display_ctx_t *ctx, const char *frame_data)
 Render an ASCII frame to the terminal.
 
void session_display_write_raw (session_display_ctx_t *ctx, const char *data, size_t len)
 Render raw bytes to the terminal without frame processing.
 
void session_display_render_fps_overlay (session_display_ctx_t *ctx)
 Render FPS counter overlay in top-right corner.
 
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.
 
void session_display_reset (session_display_ctx_t *ctx)
 Reset terminal to default state.
 
void session_display_clear (session_display_ctx_t *ctx)
 Clear the terminal screen.
 
void session_display_cursor_home (session_display_ctx_t *ctx)
 Move cursor to home position (top-left)
 
bool session_display_has_audio_playback (session_display_ctx_t *ctx)
 Check if display has audio playback configured.
 
asciichat_error_t session_display_write_audio (session_display_ctx_t *ctx, const float *buffer, size_t num_samples)
 Write audio samples to playback buffer.
 

Detailed Description

🖥️ Unified terminal display abstraction for session-based rendering

Definition in file src/common/session/display.h.

Function Documentation

◆ session_display_init_render_file()

asciichat_error_t session_display_init_render_file ( session_display_ctx_t *  ctx,
uint32_t  fps 
)

Initialize render-file output after the capture frame rate is known.

Parameters
ctxDisplay context
fpsFrame rate used for output timing
Returns
ASCIICHAT_OK on success

Initialize render-file output after the capture frame rate is known.

Executes comprehensive terminal reset sequence for clean display state. Skips terminal control operations in snapshot mode.

Parameters
snapshot_modeWhether snapshot mode is enabled

Definition at line 128 of file src/common/session/display.c.

128 {
129 if (!ctx) {
130 return SET_ERRNO(ERROR_INVALID_PARAM, "Display context is NULL");
131 }
132
133 const char *render_file_opt = GET_OPTION(render_file);
134 if (!render_file_opt || render_file_opt[0] == '\0') {
135 return ASCIICHAT_OK;
136 }
137 if (ctx->render_file) {
138 return ASCIICHAT_OK;
139 }
140
141 uint32_t encoder_fps = fps;
142 if (encoder_fps == 0) {
143 encoder_fps = (uint32_t)GET_OPTION(fps);
144 }
145 if (encoder_fps == 0) {
146 encoder_fps = 60;
147 }
148
149 int width = (int)GET_OPTION(width);
150 int height = (int)GET_OPTION(height);
151 ctx->render_fps = encoder_fps;
152
153 log_info("render-file: Initializing encoder after media timing selection: path='%s', grid=%dx%d, fps=%u",
154 render_file_opt, width, height, encoder_fps);
156 render_file_create(render_file_opt, width, height, (int)encoder_fps, GET_OPTION(render_theme), &ctx->render_file);
157 if (err != ASCIICHAT_OK) {
158 log_error("render-file: Failed to create encoder with error %d", err);
159 return err;
160 }
161
162 log_info("render-file: Encoder initialized successfully at %u FPS", encoder_fps);
163 return ASCIICHAT_OK;
164}
unsigned int uint32_t
Definition common.h:58
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it, returning the error code.
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
@ ASCIICHAT_OK
Definition error_codes.h:51
@ ERROR_INVALID_PARAM
#define log_error(...)
Log an ERROR message.
Definition log/log.h:587
#define log_info(...)
Log an INFO message.
Definition log/log.h:561
#define GET_OPTION(field)
Safely get a specific option field (lock-free read)
asciichat_error_t render_file_create(const char *output_path, int cols, int rows, int fps, int theme, render_file_ctx_t **out)
Definition renderer.c:33
render_file_ctx_t * render_file
Render-to-file context (NULL if disabled)
uint32_t render_fps
Video FPS for render-file encoding.

References ASCIICHAT_OK, ERROR_INVALID_PARAM, GET_OPTION, log_error, log_info, session_display_ctx::render_file, render_file_create(), session_display_ctx::render_fps, and SET_ERRNO.

Referenced by session_client_like_run(), and session_display_create().

◆ session_display_set_render_live_timing()

void session_display_set_render_live_timing ( session_display_ctx_t *  ctx)

Definition at line 940 of file src/common/session/display.c.

940 {
941 if (ctx && ctx->render_file)
943}
void render_file_set_live_timing(render_file_ctx_t *ctx)
Definition renderer.c:139

References session_display_ctx::render_file, and render_file_set_live_timing().

Referenced by session_pipeline_create().