|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🎬 Multi-client video mixer: frame generation, ASCII conversion, and per-client personalized rendering More...
Go to the source code of this file.
Data Structures | |
| struct | image_source_t |
| Image source structure for multi-client video mixing. More... | |
Functions | |
| char * | create_mixed_ascii_frame_for_client (uint32_t target_client_id, unsigned short width, unsigned short height, bool wants_stretch, size_t *out_size, bool *out_grid_changed, int *out_sources_count) |
| Generate personalized ASCII frame for a specific client. | |
| int | queue_audio_for_client (client_info_t *client, const void *audio_data, size_t data_size) |
| Queue ASCII frame for delivery to specific client. | |
| bool | any_clients_sending_video (void) |
| Check if any connected clients are currently sending video. | |
Variables | |
| rwlock_t | g_client_manager_rwlock |
| Reader-writer lock protecting the global client manager. | |
| client_manager_t | g_client_manager |
| Global client manager singleton - central coordination point. | |
🎬 Multi-client video mixer: frame generation, ASCII conversion, and per-client personalized rendering
The mixing system operates in several stages:
Unlike traditional video mixing that generates one output, this system creates personalized frames for each client:
TERMINAL CAPABILITY AWARENESS:
PERFORMANCE OPTIMIZATIONS:
This module operates in a high-concurrency environment:
THREAD SAFETY MECHANISMS:
PERFORMANCE CHARACTERISTICS:
DOUBLE-BUFFER STRATEGY: Each client uses a double-buffer system for smooth frame delivery:
BUFFER OVERFLOW HANDLING: When clients send frames faster than processing:
The original server.c contained all video mixing logic inline, making it:
This separation provides:
Definition in file stream.c.
| bool any_clients_sending_video | ( | void | ) |
Check if any connected clients are currently sending video.
This function scans all active clients to determine if at least one is sending video frames. Used by render threads to avoid generating frames when no video sources are available (e.g., during webcam warmup).
LOCK OPTIMIZATION: Uses atomic reads only, no rwlock acquisition This is safe because client_id, active, and is_sending_video are all atomics
Definition at line 1192 of file stream.c.
References client_info::active, client_info::client_id, client_manager_t::clients, g_client_manager, client_info::is_sending_video, and MAX_CLIENTS.
Referenced by client_video_render_thread().
| char * create_mixed_ascii_frame_for_client | ( | uint32_t | target_client_id, |
| unsigned short | width, | ||
| unsigned short | height, | ||
| bool | wants_stretch, | ||
| size_t * | out_size, | ||
| bool * | out_grid_changed, | ||
| int * | out_sources_count | ||
| ) |
Generate personalized ASCII frame for a specific client.
This is the core video mixing function that creates customized ASCII art frames for individual clients. It collects video from all active clients, creates an appropriate grid layout, and converts to ASCII using the target client's terminal capabilities.
FRAME BUFFER MANAGEMENT:
CONCURRENCY OPTIMIZATIONS:
TERMINAL AWARENESS:
RENDERING MODES SUPPORTED:
| target_client_id | Client who will receive this customized frame |
| width | Terminal width in characters for this client |
| height | Terminal height in characters for this client |
| wants_stretch | Unused parameter (aspect ratio always preserved) |
| out_size | Pointer to store resulting ASCII frame size |
Definition at line 959 of file stream.c.
References ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_TERMINAL, image_destroy_to_pool(), log_info, MAX_CLIENTS, and SET_ERRNO.
Referenced by client_video_render_thread().
| int queue_audio_for_client | ( | client_info_t * | client, |
| const void * | audio_data, | ||
| size_t | data_size | ||
| ) |
Queue ASCII frame for delivery to specific client.
Packages a generated ASCII frame into a protocol packet and queues it for asynchronous delivery to the target client. This function handles all protocol details including headers, checksums, and metadata.
| client | Target client for frame delivery |
| ascii_frame | Generated ASCII art string (null-terminated) |
| frame_size | Size of ASCII frame in bytes |
Queue audio data for delivery to specific client
Queues mixed audio data for delivery to a specific client. This is a simple wrapper around the packet queue system for audio delivery.
| client | Target client for audio delivery |
| audio_data | Mixed audio samples (float format) |
| data_size | Size of audio data in bytes |
Definition at line 1172 of file stream.c.
References client_info::audio_queue, packet_queue_enqueue(), and PACKET_TYPE_AUDIO.
|
extern |
Global client manager singleton - central coordination point.
Global client manager for signal handler access.
This is the primary data structure for managing all connected clients. It serves as the bridge between main.c's connection accept loop and the per-client threading architecture.
STRUCTURE COMPONENTS:
THREAD SAFETY: Protected by g_client_manager_rwlock for concurrent access
Definition at line 189 of file src/server/client.c.
Referenced by __attribute__(), any_clients_sending_video(), broadcast_server_state_to_all_clients(), find_client_by_socket(), send_server_state_to_client(), stats_logger_thread(), and update_server_stats().
|
extern |
Reader-writer lock protecting the global client manager.
This lock enables high-performance concurrent access patterns:
USAGE PATTERN:
Definition at line 204 of file src/server/client.c.
Referenced by __attribute__(), broadcast_server_state_to_all_clients(), find_client_by_socket(), stats_logger_thread(), and update_server_stats().