ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
comprehensive.c File Reference

Go to the source code of this file.

Typedefs

typedef void h265_encoder_t
typedef void video_frame_t
typedef void acds_client_config_t
typedef void acds_client_t
typedef void audio_context_t
typedef void client_audio_pipeline_config_t
typedef void acip_client_callbacks_t
typedef void wav_writer_t
typedef void acds_session_lookup_result_t
typedef struct audio_ring_buffer audio_ring_buffer_t
typedef struct audio_pipeline audio_pipeline_t
typedef struct client_audio_pipeline client_audio_pipeline_t
typedef void webrtc_peer_manager_t

Functions

bool socket_is_valid (socket_t sock)
int socket_close (socket_t sock)
int socket_shutdown (socket_t sock, int how)
ssize_t socket_send (socket_t sock, const void *buf, size_t len, int flags)
ssize_t socket_recv (socket_t sock, void *buf, size_t len, int flags)
int socket_poll (struct pollfd *fds, nfds_t nfds, int64_t timeout_ns)
bool socket_is_would_block_error (int error_code)
bool socket_is_invalid_socket_error (int error_code)
const char * socket_get_error_string (void)
int socket_get_last_error (void)
asciichat_error_t h265_encode (h265_encoder_t *encoder, uint16_t width, uint16_t height, const uint8_t *pixel_data, uint8_t *out_data, size_t *out_len)
void h265_encoder_destroy (h265_encoder_t *encoder)
asciichat_error_t h265_encoder_flush (h265_encoder_t *encoder, uint8_t *out_data, size_t *out_len)
void h265_encoder_request_keyframe (h265_encoder_t *encoder)
void audio_analysis_destroy (void)
 Cleanup audio analysis.
void audio_analysis_print_report (void)
 Print audio analysis report.
void audio_analysis_track_received_packet (uint32_t timestamp)
void audio_analysis_track_sent_packet (uint32_t timestamp)
void audio_analysis_track_sent_sample (float sample)
 Track sent audio sample.
void audio_analysis_track_received_sample (float sample)
 Track received audio sample.
size_t audio_ring_buffer_available_read (audio_ring_buffer_t *rb)
 Get number of samples available for reading.
void audio_set_pipeline (audio_context_t *ctx, void *pipeline)
 Set audio pipeline for echo cancellation.
asciichat_error_t audio_write_samples (void *ctx, const float *samples, int count)
asciichat_error_t audio_read_samples (void *ctx, float *buffer, int count)
client_audio_pipeline_t * client_audio_pipeline_create (const client_audio_pipeline_config_t *config)
 Create a new client audio pipeline.
void client_audio_pipeline_default_config (void)
 Audio-pipeline setup for channel conversion, Opus encoding, echo handling, and preprocessing. The channel counts, sample rate, frame duration, bitrate, and processor settings are copied into the pipeline during initialization; the config itself can then be stack-owned.
void client_audio_pipeline_destroy (client_audio_pipeline_t *pipeline)
 Destroy a client audio pipeline.
asciichat_error_t client_audio_pipeline_capture (client_audio_pipeline_t *pipeline, const float *samples, size_t count)
void client_audio_pipeline_playback (client_audio_pipeline_t *pipeline, const float *samples, size_t count)
asciichat_error_t acip_send_image_frame (acip_transport_t *transport, const void *pixel_data, uint32_t width, uint32_t height, uint32_t pixel_format)
 Send image frame to server (client → server).
asciichat_error_t acip_client_receive_and_dispatch (acip_transport_t *transport, const acip_client_callbacks_t *callbacks)
 Receive packet from server and dispatch to callbacks.
void acip_transport_destroy (acip_transport_t *transport)
 Destroy transport and free all resources.
acip_transport_t * acip_tcp_transport_create (const char *name, socket_t sockfd, crypto_context_t *crypto_ctx)
 Create TCP transport from existing socket.
bool wav_dump_enabled (void)
 Check if audio dumping is enabled via environment.
void * wav_writer_open (const char *path)
int wav_writer_write (wav_writer_t *writer, const float *samples, int num_samples)
 Write audio samples to WAV file.
void wav_writer_close (void *wav)
asciichat_error_t webrtc_peer_manager_handle_sdp (webrtc_peer_manager_t *mgr, const char *sdp)
int webrtc_peer_manager_handle_ice (webrtc_peer_manager_t *mgr, const char *candidate)
void lifecycle_destroy_commit (lifecycle_t *lc)
bool lifecycle_destroy_once (lifecycle_t *lc)
bool lifecycle_reset (lifecycle_t *lc)
void acds_client_config_init_defaults (acds_client_config_t *config)
 Initialize ACDS client configuration with defaults.
acds_client_t * acds_client_connect (const acds_client_config_t *config, void *ctx)
void acds_client_disconnect (acds_client_t *client)
 Disconnect from ACDS server.
asciichat_error_t acds_session_lookup (acds_client_t *client, const char *session_string, acds_session_lookup_result_t *result)
 Look up session by string.
asciichat_error_t thread_pool_spawn (void *pool, void *(*thread_func)(void *), void *thread_arg, int stop_id, const char *name)
asciichat_error_t thread_pool_stop_all (void *pool)
bool platform_is_interactive (void)

Typedef Documentation

◆ acds_client_config_t

typedef void acds_client_config_t

Definition at line 23 of file comprehensive.c.

◆ acds_client_t

typedef void acds_client_t

Definition at line 24 of file comprehensive.c.

◆ acds_session_lookup_result_t

typedef void acds_session_lookup_result_t

Definition at line 29 of file comprehensive.c.

◆ acip_client_callbacks_t

typedef void acip_client_callbacks_t

Definition at line 27 of file comprehensive.c.

◆ audio_context_t

typedef void audio_context_t

Definition at line 25 of file comprehensive.c.

◆ audio_pipeline_t

typedef struct audio_pipeline audio_pipeline_t

Definition at line 141 of file comprehensive.c.

◆ audio_ring_buffer_t

Definition at line 140 of file comprehensive.c.

◆ client_audio_pipeline_config_t

typedef void client_audio_pipeline_config_t

Definition at line 26 of file comprehensive.c.

◆ client_audio_pipeline_t

typedef struct client_audio_pipeline client_audio_pipeline_t

Definition at line 142 of file comprehensive.c.

◆ h265_encoder_t

typedef void h265_encoder_t

Definition at line 21 of file comprehensive.c.

◆ video_frame_t

typedef void video_frame_t

Definition at line 22 of file comprehensive.c.

◆ wav_writer_t

typedef void wav_writer_t

Definition at line 28 of file comprehensive.c.

◆ webrtc_peer_manager_t

typedef void webrtc_peer_manager_t

Definition at line 248 of file comprehensive.c.

Function Documentation

◆ acds_client_config_init_defaults()

void acds_client_config_init_defaults ( acds_client_config_t * config)

Initialize ACDS client configuration with defaults.

Sets default values:

  • server_address: "127.0.0.1"
  • server_port: 27225
  • timeout_ms: 5000
Parameters
configConfiguration to initialize

Definition at line 280 of file comprehensive.c.

280 {
281 (void)config;
282}

◆ acds_client_connect()

acds_client_t * acds_client_connect ( const acds_client_config_t * config,
void * ctx )

Definition at line 284 of file comprehensive.c.

284 {
285 (void)config;
286 (void)ctx;
287 return NULL;
288}

◆ acds_client_disconnect()

void acds_client_disconnect ( acds_client_t * client)

Disconnect from ACDS server.

Closes the connection and cleans up resources.

Parameters
clientClient handle

Definition at line 290 of file comprehensive.c.

290 {
291 (void)client;
292}

◆ acds_session_lookup()

asciichat_error_t acds_session_lookup ( acds_client_t * client,
const char * session_string,
acds_session_lookup_result_t * result )

Look up session by string.

Sends SESSION_LOOKUP packet and receives SESSION_INFO response.

Parameters
clientConnected ACDS client
session_stringSession string to look up
resultLookup result (output)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 294 of file comprehensive.c.

294 {
295 (void)client;
296 (void)session_string;
297 (void)result;
298 return SET_ERRNO(ERROR_NOT_SUPPORTED, "ACDS not supported in WASM");
299}
#define SET_ERRNO(code,...)
@ ERROR_NOT_SUPPORTED
Definition error_codes.h:73

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ acip_client_receive_and_dispatch()

asciichat_error_t acip_client_receive_and_dispatch ( acip_transport_t * transport,
const acip_client_callbacks_t * callbacks )

Receive packet from server and dispatch to callbacks.

High-level receive function for client side. Receives a single packet from the transport, handles decryption, and dispatches to appropriate callback handler.

Parameters
transportTransport instance
callbacksCallback structure for handling received packets
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 205 of file comprehensive.c.

205 {
206 (void)transport;
207 (void)callbacks;
208 return SET_ERRNO(ERROR_NOT_SUPPORTED, "ACIP not supported in WASM");
209}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ acip_send_image_frame()

asciichat_error_t acip_send_image_frame ( acip_transport_t * transport,
const void * pixel_data,
uint32_t width,
uint32_t height,
uint32_t pixel_format )

Send image frame to server (client → server).

Sends webcam video frame as RGB24 pixel data.

Parameters
transportTransport instance
pixel_dataRGB24 pixel data (width * height * 3 bytes)
widthFrame width in pixels
heightFrame height in pixels
pixel_formatPixel format (e.g., RGB24)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 196 of file comprehensive.c.

196 {
197 (void)transport;
198 (void)pixel_data;
199 (void)width;
200 (void)height;
201 (void)pixel_format;
202 return SET_ERRNO(ERROR_NOT_SUPPORTED, "ACIP not supported in WASM");
203}
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24

References ERROR_NOT_SUPPORTED, height, SET_ERRNO, and width.

◆ acip_tcp_transport_create()

acip_transport_t * acip_tcp_transport_create ( const char * name,
socket_t sockfd,
crypto_context_t * crypto_ctx )

Create TCP transport from existing socket.

Parameters
nameDebug name for tracking this transport (required, e.g., "transport_client_5")
sockfdConnected socket descriptor
crypto_ctxOptional crypto context (may be NULL)
Returns
Transport instance or NULL on error
Note
Caller retains socket ownership (transport doesn't close on destroy)

Definition at line 215 of file comprehensive.c.

215 {
216 (void)name;
217 (void)sockfd;
218 (void)crypto_ctx;
219 return NULL;
220}

◆ acip_transport_destroy()

void acip_transport_destroy ( acip_transport_t * transport)

Destroy transport and free all resources.

Parameters
transportTransport to destroy (may be NULL)
Note
Calls close() first if still connected
Frees the transport structure itself
Safe to pass NULL

Definition at line 211 of file comprehensive.c.

211 {
212 (void)transport;
213}

◆ audio_analysis_destroy()

void audio_analysis_destroy ( void )

Cleanup audio analysis.

Definition at line 118 of file comprehensive.c.

118{}

◆ audio_analysis_print_report()

void audio_analysis_print_report ( void )

Print audio analysis report.

Definition at line 120 of file comprehensive.c.

120{}

◆ audio_analysis_track_received_packet()

void audio_analysis_track_received_packet ( uint32_t timestamp)

Definition at line 122 of file comprehensive.c.

122 {
123 (void)timestamp;
124}

◆ audio_analysis_track_received_sample()

void audio_analysis_track_received_sample ( float sample)

Track received audio sample.

Parameters
sampleAudio sample value

Definition at line 134 of file comprehensive.c.

134 {
135 (void)sample;
136}

◆ audio_analysis_track_sent_packet()

void audio_analysis_track_sent_packet ( uint32_t timestamp)

Definition at line 126 of file comprehensive.c.

126 {
127 (void)timestamp;
128}

◆ audio_analysis_track_sent_sample()

void audio_analysis_track_sent_sample ( float sample)

Track sent audio sample.

Parameters
sampleAudio sample value

Definition at line 130 of file comprehensive.c.

130 {
131 (void)sample;
132}

◆ audio_read_samples()

asciichat_error_t audio_read_samples ( void * ctx,
float * buffer,
int count )

Definition at line 161 of file comprehensive.c.

161 {
162 (void)ctx;
163 (void)buffer;
164 (void)count;
165 return ASCIICHAT_OK;
166}
@ ASCIICHAT_OK
Definition error_codes.h:50

References ASCIICHAT_OK.

◆ audio_write_samples()

asciichat_error_t audio_write_samples ( void * ctx,
const float * samples,
int count )

Definition at line 154 of file comprehensive.c.

154 {
155 (void)ctx;
156 (void)samples;
157 (void)count;
158 return ASCIICHAT_OK;
159}

References ASCIICHAT_OK.

◆ client_audio_pipeline_capture()

asciichat_error_t client_audio_pipeline_capture ( client_audio_pipeline_t * pipeline,
const float * samples,
size_t count )

Definition at line 181 of file comprehensive.c.

181 {
182 (void)pipeline;
183 (void)samples;
184 (void)count;
185 return ASCIICHAT_OK;
186}

References ASCIICHAT_OK.

◆ client_audio_pipeline_create()

client_audio_pipeline_t * client_audio_pipeline_create ( const client_audio_pipeline_config_t * config)

Create a new client audio pipeline.

Parameters
configPipeline configuration (NULL for defaults)
Returns
New pipeline instance, or NULL on failure

Allocates and initializes all audio processing components. Must be destroyed with client_audio_pipeline_destroy().

Create a new client audio pipeline.

This function:

  • Allocates the pipeline structure
  • Initializes Opus encoder/decoder
  • Sets up WebRTC AEC3 echo cancellation
  • Configures all audio processing parameters

Definition at line 170 of file comprehensive.c.

170 {
171 (void)config;
172 return NULL;
173}

◆ client_audio_pipeline_default_config()

void client_audio_pipeline_default_config ( void )

Audio-pipeline setup for channel conversion, Opus encoding, echo handling, and preprocessing. The channel counts, sample rate, frame duration, bitrate, and processor settings are copied into the pipeline during initialization; the config itself can then be stack-owned.

Get default configuration

Returns
Configuration with sensible defaults for voice chat

Definition at line 175 of file comprehensive.c.

175{}

◆ client_audio_pipeline_destroy()

void client_audio_pipeline_destroy ( client_audio_pipeline_t * pipeline)

Destroy a client audio pipeline.

Parameters
pipelinePipeline to destroy (can be NULL)

Frees all resources including SpeexDSP states, Opus codec, and all work buffers.

Definition at line 177 of file comprehensive.c.

177 {
178 (void)pipeline;
179}

◆ client_audio_pipeline_playback()

void client_audio_pipeline_playback ( client_audio_pipeline_t * pipeline,
const float * samples,
size_t count )

Definition at line 188 of file comprehensive.c.

188 {
189 (void)pipeline;
190 (void)samples;
191 (void)count;
192}

◆ h265_encode()

asciichat_error_t h265_encode ( h265_encoder_t * encoder,
uint16_t width,
uint16_t height,
const uint8_t * ascii_data,
uint8_t * output_buf,
size_t * output_size )

Encode an RGB24 upload frame

The encoder automatically detects size changes and reinitializes when needed. The output packet includes frame dimensions so decoder can reconfigure.

Parameters
encoderEncoder handle
widthCurrent frame width in pixels
heightCurrent frame height in pixels
ascii_dataRGB24 pixel data (width × height × 3 bytes)
output_bufBuffer for encoded output
output_sizeInput: buffer size, Output: actual encoded size
Returns
Error code (ASCIICHAT_OK on success)

OUTPUT PACKET FORMAT: [flags: u8][width: u16][height: u16][x265_data...]

Definition at line 91 of file comprehensive.c.

91 {
92 (void)encoder;
93 (void)width;
94 (void)height;
95 (void)pixel_data;
96 (void)out_data;
97 (void)out_len;
98 return SET_ERRNO(ERROR_NOT_SUPPORTED, "H.265 encoding not supported in WASM");
99}

References ERROR_NOT_SUPPORTED, height, SET_ERRNO, and width.

◆ h265_encoder_destroy()

void h265_encoder_destroy ( h265_encoder_t * encoder)

Destroy an x265 encoder

Parameters
encoderEncoder to destroy (may be NULL)

Definition at line 101 of file comprehensive.c.

101 {
102 (void)encoder;
103}

◆ h265_encoder_flush()

asciichat_error_t h265_encoder_flush ( h265_encoder_t * encoder,
uint8_t * output_buf,
size_t * output_size )

Flush remaining buffered frames from encoder

Sends a NULL frame to the encoder to flush all buffered frames. This should be called before destroying the encoder or when you need to ensure all encoded data is retrieved.

Parameters
encoderEncoder handle
output_bufBuffer for encoded output
output_sizeInput: buffer size, Output: actual encoded size
Returns
Error code (ASCIICHAT_OK on success, ASCIICHAT_OK with size=0 when no more data)

USAGE: // After final h265_encode() call, flush remaining frames while (size > 0) { size = max_size; h265_encoder_flush(encoder, buf, &size); if (size > 0) { // Send the flushed frame... } }

Definition at line 105 of file comprehensive.c.

105 {
106 (void)encoder;
107 (void)out_data;
108 (void)out_len;
109 return ASCIICHAT_OK;
110}

References ASCIICHAT_OK.

◆ h265_encoder_request_keyframe()

void h265_encoder_request_keyframe ( h265_encoder_t * encoder)

Request a keyframe on the next encode

Forces the encoder to produce an I-frame (keyframe) on the next call to h265_encoder_encode(). Useful for error recovery or stream synchronization.

Parameters
encoderEncoder handle

Definition at line 112 of file comprehensive.c.

112 {
113 (void)encoder;
114}

◆ lifecycle_destroy_commit()

void lifecycle_destroy_commit ( lifecycle_t * lc)

Definition at line 264 of file comprehensive.c.

264 {
265 (void)lc;
266}

Referenced by ui_controller_shutdown(), and ui_input_shutdown().

◆ lifecycle_destroy_once()

bool lifecycle_destroy_once ( lifecycle_t * lc)

Definition at line 268 of file comprehensive.c.

268 {
269 (void)lc;
270 return true;
271}

Referenced by ui_controller_shutdown(), and ui_input_shutdown().

◆ lifecycle_reset()

bool lifecycle_reset ( lifecycle_t * lc)

Definition at line 273 of file comprehensive.c.

273 {
274 (void)lc;
275 return true;
276}

◆ platform_is_interactive()

bool platform_is_interactive ( void )

Definition at line 319 of file comprehensive.c.

319 {
320 return false;
321}

Referenced by ui_input_password().

◆ socket_close()

int socket_close ( socket_t sock)

Definition at line 37 of file comprehensive.c.

37 {
38 (void)sock;
39 return 0;
40}

Referenced by asciichat_mdns_advertise(), https_get(), parallel_connect(), quic_udp_endpoint_create(), quic_udp_endpoint_destroy(), and tcp_server_destroy().

◆ socket_get_error_string()

const char * socket_get_error_string ( void )

Definition at line 81 of file comprehensive.c.

81 {
82 return "Socket error";
83}

Referenced by accept_with_timeout(), and network_error_string().

◆ socket_get_last_error()

int socket_get_last_error ( void )

Definition at line 85 of file comprehensive.c.

85 {
86 return 0;
87}

Referenced by accept_with_timeout(), connect_with_timeout(), and quic_udp_pump().

◆ socket_is_invalid_socket_error()

bool socket_is_invalid_socket_error ( int error_code)

Definition at line 76 of file comprehensive.c.

76 {
77 (void)error_code;
78 return false;
79}

Referenced by accept_with_timeout().

◆ socket_is_valid()

bool socket_is_valid ( socket_t sock)

Definition at line 33 of file comprehensive.c.

33 {
34 return sock >= 0;
35}

◆ socket_is_would_block_error()

bool socket_is_would_block_error ( int error_code)

Definition at line 71 of file comprehensive.c.

71 {
72 (void)error_code;
73 return false;
74}

Referenced by connect_with_timeout(), and quic_udp_pump().

◆ socket_poll()

int socket_poll ( struct pollfd * fds,
nfds_t nfds,
int64_t timeout_ns )

Definition at line 64 of file comprehensive.c.

64 {
65 (void)fds;
66 (void)nfds;
67 (void)timeout_ns;
68 return 0;
69}

Referenced by accept_with_timeout(), asciichat_mdns_update(), quic_udp_wait(), recv_with_timeout(), and send_with_timeout().

◆ socket_recv()

ssize_t socket_recv ( socket_t sock,
void * buf,
size_t len,
int flags )

Definition at line 56 of file comprehensive.c.

56 {
57 (void)sock;
58 (void)buf;
59 (void)len;
60 (void)flags;
61 return -1;
62}

Referenced by recv_with_timeout().

◆ socket_send()

ssize_t socket_send ( socket_t sock,
const void * buf,
size_t len,
int flags )

Definition at line 48 of file comprehensive.c.

48 {
49 (void)sock;
50 (void)buf;
51 (void)len;
52 (void)flags;
53 return -1;
54}

Referenced by send_with_timeout().

◆ socket_shutdown()

int socket_shutdown ( socket_t sock,
int how )

Definition at line 42 of file comprehensive.c.

42 {
43 (void)sock;
44 (void)how;
45 return 0;
46}

◆ thread_pool_spawn()

asciichat_error_t thread_pool_spawn ( void * pool,
void *(* thread_func )(void *),
void * thread_arg,
int stop_id,
const char * name )

Definition at line 303 of file comprehensive.c.

303 {
304 (void)pool;
305 (void)thread_func;
306 (void)thread_arg;
307 (void)stop_id;
308 (void)name;
309 return ASCIICHAT_OK; // No-op in WASM (no real threads)
310}

References ASCIICHAT_OK.

◆ thread_pool_stop_all()

asciichat_error_t thread_pool_stop_all ( void * pool)

Definition at line 312 of file comprehensive.c.

312 {
313 (void)pool;
314 return ASCIICHAT_OK; // No-op in WASM
315}

References ASCIICHAT_OK.

◆ wav_dump_enabled()

bool wav_dump_enabled ( void )

Check if audio dumping is enabled via environment.

Returns
true if ASCIICHAT_DUMP_AUDIO=1

Definition at line 226 of file comprehensive.c.

226 {
227 return false;
228}

◆ wav_writer_close()

void wav_writer_close ( void * wav)

Definition at line 242 of file comprehensive.c.

242 {
243 (void)wav;
244}

◆ wav_writer_open()

void * wav_writer_open ( const char * path)

Definition at line 230 of file comprehensive.c.

230 {
231 (void)path;
232 return NULL;
233}

◆ wav_writer_write()

int wav_writer_write ( wav_writer_t * writer,
const float * samples,
int num_samples )

Write audio samples to WAV file.

Parameters
writerWAV writer context
samplesFloat samples in range [-1.0, 1.0]
num_samplesNumber of samples to write
Returns
0 on success, -1 on error

Definition at line 235 of file comprehensive.c.

235 {
236 (void)writer;
237 (void)samples;
238 (void)num_samples;
239 return 0;
240}

◆ webrtc_peer_manager_handle_ice()

int webrtc_peer_manager_handle_ice ( webrtc_peer_manager_t * mgr,
const char * candidate )

Definition at line 256 of file comprehensive.c.

256 {
257 (void)mgr;
258 (void)candidate;
259 return -1;
260}

◆ webrtc_peer_manager_handle_sdp()

asciichat_error_t webrtc_peer_manager_handle_sdp ( webrtc_peer_manager_t * mgr,
const char * sdp )

Definition at line 250 of file comprehensive.c.

250 {
251 (void)mgr;
252 (void)sdp;
253 return SET_ERRNO(ERROR_NOT_SUPPORTED, "WebRTC not supported in WASM");
254}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.