ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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
7
8#include <stdbool.h>
9#include <stdint.h>
10#include <time.h>
11
12#include <libplatform/atomic.h>
15#include <ascii-chat/network/acip/transport.h> // For acip_transport_t
17#include <ascii-chat/crypto/handshake/common.h> // For crypto_handshake_context_t (complete type needed for field)
20#include <libplatform/terminal.h>
21#include <libplatform/thread.h> // For thread_id_t
26
35typedef enum {
36 PARTICIPANT_TYPE_NETWORK, // Remote participant via socket/transport
37 PARTICIPANT_TYPE_MEMORY // Local host participant (direct memory access)
39
40typedef struct client_info {
41 participant_type_t participant_type; // Network (socket) or memory (direct injection)
43 atomic_t event_ready;
44 atomic_t event_cleanup;
45 acip_transport_t *transport; // ACIP transport for protocol-agnostic packet sending
46 void *server_ctx; // Pointer to server_context_t (avoid circular includes)
47 char client_id[MAX_CLIENT_ID_LEN]; // String-based client ID: "noun.N (transport:port)"
48 uint32_t session_client_id; // Session host client ID (0 if not registered)
50 char client_ip[INET_ADDRSTRLEN];
51 int port;
52
53 atomic_t supports_recoverable_errors; // Negotiated optional error notifications
54
55 // Media capabilities
58 bool wants_stretch; // Client wants stretched output (ignore aspect ratio)
59 atomic_t is_sending_video; // Thread-safe video stream state
60 atomic_t is_sending_audio; // Thread-safe audio stream state
61
62 // Codec capabilities (from CLIENT_CAPABILITIES packet)
63 uint32_t codec_capabilities_video; // VIDEO_CODEC_CAP_* bitmask
64 uint32_t codec_capabilities_audio; // AUDIO_CODEC_CAP_* bitmask
65
66 // Opus codec for audio compression/decompression
67 void *opus_decoder; // opus_codec_t* - Opus decoder for this client's audio
68
69 // Video decoder (persistent across frames for proper video decoding)
70 void *video_decoder_ctx; // AVCodecContext* - H.264/HEVC decoder for this client
71 void *video_decode_frame; // AVFrame* - Persistent frame for video decoding
72 void *video_rgb_frame; // AVFrame* - RGB frame for color space conversion
73 void *video_sws_ctx; // SwsContext* - Color space converter for YUV->RGB
74
75 // Terminal capabilities (for rendering appropriate ASCII frames)
78 terminal_capabilities_t terminal_caps;
79 bool has_terminal_caps; // Whether we've received terminal capabilities from this client
80
81 // Per-client palette cache
82 char client_palette_chars[ASCII_PALETTE_BUFFER_SIZE]; // Client's palette characters
83 size_t client_palette_len; // Length of client's palette
84 char client_luminance_palette[ASCII_LUMINANCE_LEVELS]; // Client's luminance-to-character mapping
85 palette_type_t client_palette_type; // Client's palette type
86 bool client_palette_initialized; // Whether client's palette is set up
87
88 // Per-client state for Matrix Rain post-processing of generated ASCII.
91
92 // Stream dimensions
94
95 // Statistics
96 atomic_t active;
97 atomic_t shutting_down; // Set when client is being removed
98 atomic_t protocol_disconnect_requested; // Set when protocol violation requires disconnect
101 uint64_t frames_received; // Track incoming frames from this client
102 uint32_t frames_received_logged; // Track for periodic logging (thread-safe via client_state_mutex)
105 uint32_t last_received_frame_hash; // Hash of last frame received from this client
106
107 // Buffers for incoming media (individual per client)
108 video_frame_buffer_t *incoming_video_buffer; // Modern double-buffered video frame
109 audio_ring_buffer_t *incoming_audio_buffer; // Buffer for this client's audio
110
111 // Tracks the last source layout submitted to the shared send scheduler.
113
114 // Frame statistics for debugging
115 atomic_t frames_sent_count; // Total ASCII frames sent to this client
116
117 // Per-client rendering threads
118 platform_thread_t video_render_thread;
119 platform_thread_t audio_render_thread;
122
123 // Per-client synchronization
125 mutex_t send_mutex; // Serializes application control and media transitions
126
127 // Borrowed from the owning network connection; valid until producer threads join.
131 bool security_ready; // Negotiation and any required authentication completed
132 bool encrypt_data; // Whether payload encryption is enabled (false = auth-only mode)
133
134 // uthash handle for hash table operations
135 UT_hash_handle hh;
Common declarations and data structures for cryptographic handshake.
Matrix-style digital rain effect for ASCII frames.
unsigned short uint16_t
Definition common.h:61
unsigned int uint32_t
Definition common.h:62
unsigned long long uint64_t
Definition common.h:63
#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:90
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:506
struct client_info client_info_t
#define ASCII_LUMINANCE_LEVELS
Number of luminance levels supported (256).
Definition ascii.h:440
#define ASCII_PALETTE_BUFFER_SIZE
struct digital_rain digital_rain_t
Digital rain effect context.
🔊 Audio Capture and Playback Interface for ascii-chat
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
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,...
bool transport_encrypted
TLS or DTLS already encrypts this client's transport.
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
SIMD-optimized ASCII conversion interface.