ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
include/ascii-chat/network/client.h
Go to the documentation of this file.
3#pragma once
8
9#include <stdbool.h>
10#include <stdint.h>
11#include <time.h>
12
14#include <ascii-chat/crypto/handshake/common.h> // For crypto_handshake_context_t (complete type needed for field)
15#include <ascii-chat/network/acip/transport.h> // For acip_transport_t
24#include <libplatform/atomic.h>
25#include <libplatform/terminal.h>
26#include <libplatform/thread.h> // For thread_id_t
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
43typedef enum {
44 PARTICIPANT_TYPE_NETWORK, // Remote participant via socket/transport
45 PARTICIPANT_TYPE_MEMORY // Local host participant (direct memory access)
47
48typedef struct client_info {
50 participant_type; // Network (socket) or memory (direct injection)
55 *transport; // ACIP transport for protocol-agnostic packet sending
56 void *server_ctx; // Pointer to server_context_t (avoid circular includes)
57 char client_id[MAX_CLIENT_ID_LEN]; // String-based client ID: "noun.N
58 // (transport:port)"
59 uint32_t session_client_id; // Session host client ID (0 if not registered)
61 char client_ip[INET_ADDRSTRLEN];
62 int port;
63
65 supports_recoverable_errors; // Negotiated optional error notifications
66
67 // Media capabilities
70 bool wants_stretch; // Client wants stretched output (ignore aspect ratio)
71 atomic_t is_sending_video; // Thread-safe video stream state
72 atomic_t is_sending_audio; // Thread-safe audio stream state
73
74 // Codec capabilities (from CLIENT_CAPABILITIES packet)
75 uint32_t codec_capabilities_video; // VIDEO_CODEC_CAP_* bitmask
76 uint32_t codec_capabilities_audio; // AUDIO_CODEC_CAP_* bitmask
77
78 // Opus codec for audio compression/decompression
79 void *opus_decoder; // opus_codec_t* - Opus decoder for this client's audio
80
81 // Video decoder (persistent across frames for proper video decoding)
82 void *
83 video_decoder_ctx; // AVCodecContext* - H.264/HEVC decoder for this client
84 void *video_decode_frame; // AVFrame* - Persistent frame for video decoding
85 void *video_rgb_frame; // AVFrame* - RGB frame for color space conversion
86 void *video_sws_ctx; // SwsContext* - Color space converter for YUV->RGB
87
88 // Terminal capabilities (for rendering appropriate ASCII frames)
91 terminal_capabilities_t terminal_caps;
92 bool has_terminal_caps; // Whether we've received terminal capabilities from
93 // this client
94
95 // Per-client palette cache
97 // characters
98 size_t client_palette_len; // Length of client's palette
100 [ASCII_LUMINANCE_LEVELS]; // Client's luminance-to-character mapping
101 palette_type_t client_palette_type; // Client's palette type
102 bool client_palette_initialized; // Whether client's palette is set up
103
104 // Per-client state for Matrix Rain post-processing of generated ASCII.
107
108 // Stream dimensions
110
111 // Statistics
113 atomic_t shutting_down; // Set when client is being removed
114 atomic_t protocol_disconnect_requested; // Set when protocol violation
115 // requires disconnect
118 uint64_t frames_received; // Track incoming frames from this client
119 uint32_t frames_received_logged; // Track for periodic logging (thread-safe
120 // via client_state_mutex)
124 last_received_frame_hash; // Hash of last frame received from this client
125
126 // Buffers for incoming media (individual per client)
128 *incoming_video_buffer; // Modern double-buffered video frame
129 audio_ring_buffer_t *incoming_audio_buffer; // Buffer for this client's audio
130
131 // Tracks the last source layout submitted to the shared send scheduler.
133
134 // Frame statistics for debugging
135 atomic_t frames_sent_count; // Total ASCII frames sent to this client
136
137 // Per-client rendering threads
138 platform_thread_t video_render_thread;
139 platform_thread_t audio_render_thread;
142
143 // Per-client synchronization
145 mutex_t send_mutex; // Serializes application control and media transitions
146
147 // Borrowed from the owning network connection; valid until producer threads
148 // join.
153 bool security_ready; // Negotiation and any required authentication completed
154 bool encrypt_data; // Whether payload encryption is enabled (false = auth-only
155 // mode)
156
157 // uthash handle for hash table operations
158 UT_hash_handle hh;
160
161#ifdef __cplusplus
162}
163#endif
Matrix-style digital rain effect for ASCII frames.
unsigned short uint16_t
unsigned int uint32_t
unsigned long long uint64_t
#define MAX_DISPLAY_NAME_LEN
Maximum display name length in characters.
#define MAX_CLIENT_ID_LEN
Maximum client ID length - format: "noun.N (transport:port)" e.g., "mountain.0 (tcp:48036)".
palette_type_t
Built-in palette type enumeration.
Definition palette.h:96
struct audio_ring_buffer audio_ring_buffer_t
Audio ring buffer for real-time audio streaming.
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:508
struct client_info client_info_t
#define ASCII_LUMINANCE_LEVELS
Number of luminance levels supported (256).
Definition ascii.h:438
struct digital_rain digital_rain_t
Digital rain effect context.
🔊 Audio Capture and Playback Interface for ascii-chat
Common declarations and data structures for cryptographic handshake.
Transport abstraction layer for ACIP protocol.
participant_type_t
For client info, this is the live record that ties participant_type, network_connection,...
struct network_connection network_connection_t
SIMD-optimized ASCII conversion interface.
ASCII Palette Management for Video-to-ASCII Conversion.
Lock-Free Ring Buffer and Frame Buffer Management.
acip render settings keeps the values that move through the subsystem: caps, width,...
Atomic value wrapper for integral/boolean types.
Definition atomic.h:80
terminal_capabilities_t terminal_caps
char display_name[MAX_DISPLAY_NAME_LEN]
crypto_handshake_context_t * crypto_handshake_ctx
network_connection_t * network_connection
acip_render_settings_t render_settings
video_frame_buffer_t * incoming_video_buffer
platform_thread_t audio_render_thread
participant_type_t participant_type
audio_ring_buffer_t * incoming_audio_buffer
platform_thread_t video_render_thread
char client_palette_chars[ASCII_PALETTE_BUFFER_SIZE]
char client_ip[INET_ADDRSTRLEN]
char client_luminance_palette[ASCII_LUMINANCE_LEVELS]
ascii_stabilizer_t render_stabilizer
char client_id[MAX_CLIENT_ID_LEN]
Cryptographic handshake context structure.
One captured, decoded, or rendered video frame and its timing metadata.
⏱️ High-precision timing utilities using sokol_time.h and uthash