|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
📷 Cross-platform webcam capture API More...
Files | |
| file | webcam_v4l2.c |
| 📷 Linux V4L2 webcam capture implementation with MJPEG/YUY2 format support | |
| file | webcam_avfoundation.m |
| 📷 macOS AVFoundation webcam capture implementation with hardware acceleration | |
| file | webcam_mediafoundation.c |
| 📷 Windows Media Foundation webcam capture with hardware acceleration support | |
Data Structures | |
| struct | webcam_device_info_t |
| Webcam device information structure. More... | |
Macros | |
| #define | WEBCAM_DEVICE_NAME_MAX 256 |
| Maximum length of webcam device name. | |
Typedefs | |
| typedef struct webcam_context_t | webcam_context_t |
| Opaque webcam context structure. | |
Functions | |
| asciichat_error_t | webcam_list_devices (webcam_device_info_t **devices, unsigned int *count) |
| Enumerate available webcam devices. | |
| void | webcam_free_device_list (webcam_device_info_t *devices) |
| Free device list returned by webcam_list_devices() | |
| asciichat_error_t | webcam_init (unsigned short int webcam_index) |
| Initialize global webcam interface. | |
| image_t * | webcam_read (void) |
| Capture a frame from global webcam. | |
| void | webcam_cleanup (void) |
| Clean up global webcam interface. | |
| void | webcam_flush (void) |
| Flush/interrupt any pending webcam read operations. | |
| void | webcam_print_init_error_help (asciichat_error_t error_code) |
| Print helpful error diagnostics for webcam initialization failures. | |
| asciichat_error_t | webcam_init_context (webcam_context_t **ctx, unsigned short int device_index) |
| Initialize webcam context for advanced operations. | |
| void | webcam_cleanup_context (webcam_context_t *ctx) |
| Clean up webcam context and release resources. | |
| void | webcam_flush_context (webcam_context_t *ctx) |
| Flush/interrupt pending read operations on webcam context. | |
| image_t * | webcam_read_context (webcam_context_t *ctx) |
| Capture a frame from webcam context. | |
| asciichat_error_t | webcam_get_dimensions (webcam_context_t *ctx, int *width, int *height) |
| Get webcam frame dimensions. | |
📷 Cross-platform webcam capture API
This header provides a cross-platform webcam capture interface for ascii-chat. The system abstracts platform-specific webcam APIs (Windows Media Foundation, Linux V4L2, macOS AVFoundation) behind a unified interface for video frame capture.
The webcam system uses a context-based architecture:
The system supports:
The webcam module (lib/video/webcam/) provides cross-platform webcam capture with platform-specific implementations:
Each platform has its own webcam API with different capabilities and performance:
Implementation: lib/video/webcam/macos/webcam_avfoundation.m (Objective-C)
API: AVFoundation framework (modern, recommended by Apple)
Capabilities:
Supported Resolutions:
Pixel Formats:
Performance:
Implementation Example:
Implementation: lib/video/webcam/linux/webcam_v4l2.c (C)
API: Video4Linux2 kernel interface (standard Linux video API)
Capabilities:
Supported Pixel Formats:
Device Enumeration:
Memory-Mapped Capture:
Performance:
Implementation: lib/video/webcam/windows/webcam_mediafoundation.c (C++)
API: Media Foundation (modern Windows multimedia API, Vista+)
Capabilities:
Supported Pixel Formats:
Device Enumeration:
Capture with Source Reader:
Performance:
ascii-chat provides a unified C API across all platforms:
Usage example:
CPU capability detection for SIMD optimization:
x86/x86_64:
Implementation uses CPUID instruction:
ARM/ARM64:
Implementation reads /proc/cpuinfo on Linux, sysctlbyname on macOS:
Windows:
macOS:
Linux:
| #define WEBCAM_DEVICE_NAME_MAX 256 |
| typedef struct webcam_context_t webcam_context_t |
#include <webcam.h>
Opaque webcam context structure.
Forward declaration of webcam context for context-based operations. Context provides per-webcam state management for advanced scenarios.
| void webcam_cleanup | ( | void | ) |
#include <webcam.h>
Clean up global webcam interface.
Cleans up the global webcam interface and releases resources. Closes the webcam device and frees all associated memory.
Definition at line 204 of file webcam.c.
References GET_OPTION, log_info, and webcam_cleanup_context().
Referenced by ascii_read_destroy(), capture_cleanup(), and mirror_main().
| void webcam_cleanup_context | ( | webcam_context_t * | ctx | ) |
#include <webcam.h>
Clean up webcam context and release resources.
| ctx | Webcam context to clean up (can be NULL) |
Cleans up a webcam context and releases all associated resources. Closes the webcam device, frees memory, and invalidates the context.
Definition at line 313 of file webcam.c.
References log_warn.
Referenced by webcam_cleanup().
| void webcam_flush | ( | void | ) |
#include <webcam.h>
Flush/interrupt any pending webcam read operations.
Cancels any blocking ReadSample operations. Call this before stopping the capture thread to allow it to exit cleanly.
Definition at line 219 of file webcam.c.
References GET_OPTION, and webcam_flush_context().
Referenced by capture_stop_thread().
| void webcam_flush_context | ( | webcam_context_t * | ctx | ) |
#include <webcam.h>
Flush/interrupt pending read operations on webcam context.
| ctx | Webcam context (may be NULL - no-op) |
Cancels any blocking read operations. Call before stopping capture thread.
Definition at line 318 of file webcam.c.
Referenced by webcam_flush().
| void webcam_free_device_list | ( | webcam_device_info_t * | devices | ) |
#include <webcam.h>
Free device list returned by webcam_list_devices()
| devices | Device list to free (can be NULL) |
Frees a device list allocated by webcam_list_devices(). Safe to call with NULL pointer (no-op).
Definition at line 344 of file webcam.c.
Referenced by action_list_webcams().
| asciichat_error_t webcam_get_dimensions | ( | webcam_context_t * | ctx, |
| int * | width, | ||
| int * | height | ||
| ) |
#include <webcam.h>
Get webcam frame dimensions.
| ctx | Webcam context (must not be NULL) |
| width | Output pointer for frame width (must not be NULL) |
| height | Output pointer for frame height (must not be NULL) |
Queries the webcam context for current frame dimensions. Returns the width and height in pixels as determined during format negotiation with the webcam hardware.
Definition at line 329 of file webcam.c.
References ERROR_WEBCAM, and SET_ERRNO.
Referenced by webcam_init().
| asciichat_error_t webcam_init | ( | unsigned short int | webcam_index | ) |
#include <webcam.h>
Initialize global webcam interface.
| webcam_index | Webcam device index (0 for default device) |
Initializes the global webcam interface for simple single-webcam access. Opens the specified webcam device and prepares it for frame capture. This is a convenience wrapper around webcam_init_context() for simple single-webcam scenarios.
Definition at line 18 of file webcam.c.
References ASCIICHAT_OK, ERROR_WEBCAM, GET_OPTION, log_info, SET_ERRNO, webcam_get_dimensions(), and webcam_init_context().
Referenced by ascii_read_init(), capture_init(), and mirror_main().
| asciichat_error_t webcam_init_context | ( | webcam_context_t ** | ctx, |
| unsigned short int | device_index | ||
| ) |
#include <webcam.h>
Initialize webcam context for advanced operations.
| ctx | Output pointer to webcam context (must not be NULL) |
| device_index | Webcam device index (0 for default device) |
Initializes a new webcam context for context-based webcam management. This allows multiple webcams to be used simultaneously or provides more control over webcam lifecycle. Context must be cleaned up with webcam_cleanup_context() when done.
Definition at line 306 of file webcam.c.
References ERROR_WEBCAM, and SET_ERRNO.
Referenced by webcam_init().
| asciichat_error_t webcam_list_devices | ( | webcam_device_info_t ** | devices, |
| unsigned int * | count | ||
| ) |
#include <webcam.h>
Enumerate available webcam devices.
| devices | Output pointer to array of device info structures (must not be NULL) |
| count | Output pointer to number of devices found (must not be NULL) |
Enumerates all available webcam devices and returns their information. The devices array is allocated by this function and must be freed with webcam_free_device_list().
Example:
Definition at line 336 of file webcam.c.
References ERROR_WEBCAM, and SET_ERRNO.
Referenced by action_list_webcams().
| void webcam_print_init_error_help | ( | asciichat_error_t | error_code | ) |
#include <webcam.h>
Print helpful error diagnostics for webcam initialization failures.
| error_code | Error code from webcam_init() or webcam_init_context() |
Prints human-readable error diagnostics to help diagnose webcam initialization failures. Includes platform-specific troubleshooting advice for common issues (permission denied, device in use, etc.).
Definition at line 229 of file webcam.c.
References error_code, ERROR_WEBCAM, ERROR_WEBCAM_IN_USE, ERROR_WEBCAM_PERMISSION, and safe_fprintf().
Referenced by client_main(), and mirror_main().
| image_t * webcam_read | ( | void | ) |
#include <webcam.h>
Capture a frame from global webcam.
Captures a single video frame from the global webcam interface. Returns an image_t structure containing the frame data in RGB format. The image is automatically converted from native webcam format to RGB.
Definition at line 57 of file webcam.c.
References ERROR_MEMORY, ERROR_WEBCAM, GET_OPTION, image_t::h, image_new(), image_t::pixels, SET_ERRNO, image_t::w, and webcam_read_context().
Referenced by mirror_main().
| image_t * webcam_read_context | ( | webcam_context_t * | ctx | ) |
#include <webcam.h>
Capture a frame from webcam context.
| ctx | Webcam context (must not be NULL) |
Captures a single video frame from the specified webcam context. Returns an image_t structure containing the frame data in RGB format. The image is automatically converted from native webcam format to RGB.
Definition at line 323 of file webcam.c.
References ERROR_WEBCAM, and SET_ERRNO.
Referenced by webcam_read().