+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* |
| 2 | * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0 |
| 3 | * Copyright (c) 2026 Saif Mukhtar |
| 4 | * |
| 5 | * OpenAVX - Open Audio-Video eXchange |
| 6 | * include/openavx.h - Primary public C API |
| 7 | */ |
| 8 | |
| 9 | #ifndef OPENAVX_H |
| 10 | #define OPENAVX_H |
| 11 | |
| 12 | #include <stdint.h> |
| 13 | #include <stdbool.h> |
| 14 | #include <stddef.h> |
| 15 | |
| 16 | #if defined(_WIN32) |
| 17 | #ifdef OPENAVX_EXPORTS |
| 18 | #define OPENAVX_API __declspec(dllexport) |
| 19 | #else |
| 20 | #define OPENAVX_API __declspec(dllimport) |
| 21 | #endif |
| 22 | #else |
| 23 | #define OPENAVX_API __attribute__((visibility("default"))) |
| 24 | #endif |
| 25 | |
| 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
| 30 | /* Rational Number Representation */ |
| 31 | typedef struct oavx_rational { |
| 32 | uint32_t num; |
| 33 | uint32_t den; |
| 34 | } oavx_rational_t; |
| 35 | |
| 36 | /* FourCC Definitions for Video */ |
| 37 | typedef enum oavx_fourcc_video_type_e { |
| 38 | OAVX_FOURCC_VIDEO_TYPE_UYVY = 0x59565955, /* "UYVY" */ |
| 39 | OAVX_FOURCC_VIDEO_TYPE_BGRA = 0x41524742, /* "BGRA" */ |
| 40 | OAVX_FOURCC_VIDEO_TYPE_BGRX = 0x58524742, /* "BGRX" */ |
| 41 | OAVX_FOURCC_VIDEO_TYPE_RGBA = 0x41424752, /* "RGBA" */ |
| 42 | OAVX_FOURCC_VIDEO_TYPE_RGBX = 0x58424752, /* "RGBX" */ |
| 43 | OAVX_FOURCC_VIDEO_TYPE_UYVA = 0x41565955, /* "UYVA" */ |
| 44 | OAVX_FOURCC_VIDEO_TYPE_P216 = 0x36313250, /* "P216" 16-bit 4:2:2 */ |
| 45 | OAVX_FOURCC_VIDEO_TYPE_PA16 = 0x36314150, /* "PA16" 16-bit 4:2:2:4 */ |
| 46 | OAVX_FOURCC_VIDEO_TYPE_YV12 = 0x32315659, /* "YV12" */ |
| 47 | OAVX_FOURCC_VIDEO_TYPE_I420 = 0x30323449, /* "I420" */ |
| 48 | OAVX_FOURCC_VIDEO_TYPE_NV12 = 0x3231564E, /* "NV12" */ |
| 49 | |
| 50 | /* SpeedHQ Intra-DCT Compressed FourCCs */ |
| 51 | OAVX_FOURCC_VIDEO_TYPE_SHQ0 = 0x30514853, /* "SHQ0" 4:2:0 */ |
| 52 | OAVX_FOURCC_VIDEO_TYPE_SHQ1 = 0x31514853, /* "SHQ1" 4:2:0 + Alpha */ |
| 53 | OAVX_FOURCC_VIDEO_TYPE_SHQ2 = 0x32514853, /* "SHQ2" 4:2:2 Standard */ |
| 54 | OAVX_FOURCC_VIDEO_TYPE_SHQ3 = 0x33514853, /* "SHQ3" 4:2:2 + Alpha */ |
| 55 | OAVX_FOURCC_VIDEO_TYPE_SHQ4 = 0x34514853, /* "SHQ4" 4:4:4 */ |
| 56 | OAVX_FOURCC_VIDEO_TYPE_SHQ5 = 0x35514853, /* "SHQ5" 4:4:4 + Alpha */ |
| 57 | OAVX_FOURCC_VIDEO_TYPE_SHQ7 = 0x37514853, /* "SHQ7" 4:2:2 Alpha luma */ |
| 58 | OAVX_FOURCC_VIDEO_TYPE_SHQ9 = 0x39514853, /* "SHQ9" 4:4:4 Alpha luma */ |
| 59 | |
| 60 | /* Compressed FourCCs (H.264 / HEVC / AV1 / MJPEG) */ |
| 61 | OAVX_FOURCC_VIDEO_TYPE_H264 = 0x34363248, /* "H264" */ |
| 62 | OAVX_FOURCC_VIDEO_TYPE_HEVC = 0x43564548, /* "HEVC" */ |
| 63 | OAVX_FOURCC_VIDEO_TYPE_AV01 = 0x31305641, /* "AV01" */ |
| 64 | OAVX_FOURCC_VIDEO_TYPE_MJPEG = 0x47504A4D, /* "MJPG" */ |
| 65 | OAVX_FOURCC_VIDEO_TYPE_COUNT = 21 |
| 66 | } oavx_fourcc_video_type_e; |
| 67 | |
| 68 | typedef oavx_fourcc_video_type_e oavx_fourcc_t; |
| 69 | |
| 70 | /* FourCC Definitions for Audio */ |
| 71 | typedef enum oavx_fourcc_audio_type_e { |
| 72 | OAVX_FOURCC_AUDIO_TYPE_FLTP = 0x50544C46, /* "FLTP" 32-bit floating point */ |
| 73 | OAVX_FOURCC_AUDIO_TYPE_OPUS = 0x5355504F, /* "OPUS" Opus compressed audio */ |
| 74 | OAVX_FOURCC_AUDIO_TYPE_ADPC = 0x43504441, /* "ADPC" IMA ADPCM 4:1 audio */ |
| 75 | OAVX_FOURCC_AUDIO_TYPE_COUNT = 3 |
| 76 | } oavx_fourcc_audio_type_e; |
| 77 | |
| 78 | /* Audio Compression Operating Modes */ |
| 79 | typedef enum oavx_audio_compression_mode_e { |
| 80 | OAVX_AUDIO_COMPRESSION_OFF = 0, /* Always uncompressed 32-bit float PCM */ |
| 81 | OAVX_AUDIO_COMPRESSION_MANUAL = 1, /* Always compressed (Opus if available, ADPCM fallback) */ |
| 82 | OAVX_AUDIO_COMPRESSION_ADAPTIVE = 2 /* Uncompressed on clean LAN; auto-compresses under congestion */ |
| 83 | } oavx_audio_compression_mode_e; |
| 84 | |
| 85 | typedef oavx_audio_compression_mode_e oavx_audio_compression_mode_t; |
| 86 | |
| 87 | /* Standard SMPTE Scan / Interlacing Types */ |
| 88 | typedef enum oavx_scan_type_e { |
| 89 | OAVX_SCAN_PROGRESSIVE = 0, |
| 90 | OAVX_SCAN_TOP_FIELD_FIRST = 1, |
| 91 | OAVX_SCAN_BOTTOM_FIELD_FIRST = 2, |
| 92 | OAVX_SCAN_COUNT = 3 |
| 93 | } oavx_scan_type_e; |
| 94 | |
| 95 | typedef oavx_scan_type_e oavx_scan_type_t; |
| 96 | |
| 97 | /* Audio Format Types */ |
| 98 | typedef enum oavx_audio_format_e { |
| 99 | OAVX_AUDIO_FMT_FLT_PLANAR = 0, |
| 100 | OAVX_AUDIO_FMT_FLT_INTERLEAVED = 1, |
| 101 | OAVX_AUDIO_FMT_S16_INTERLEAVED = 2, |
| 102 | OAVX_AUDIO_FMT_S32_INTERLEAVED = 3, |
| 103 | OAVX_AUDIO_FMT_COUNT = 4 |
| 104 | } oavx_audio_format_e; |
| 105 | |
| 106 | typedef oavx_audio_format_e oavx_audio_format_t; |
| 107 | |
| 108 | /* Frame Types returned by Receiver / Sender */ |
| 109 | typedef enum oavx_frame_type_e { |
| 110 | OAVX_FRAME_TYPE_NONE = 0, |
| 111 | OAVX_FRAME_TYPE_VIDEO = 1, |
| 112 | OAVX_FRAME_TYPE_AUDIO = 2, |
| 113 | OAVX_FRAME_TYPE_METADATA = 3, |
| 114 | OAVX_FRAME_TYPE_ERROR = 4, |
| 115 | OAVX_FRAME_TYPE_STATUS_CHANGE = 5, |
| 116 | OAVX_FRAME_TYPE_COUNT = 6 |
| 117 | } oavx_frame_type_e; |
| 118 | |
| 119 | typedef oavx_frame_type_e oavx_frame_type_t; |
| 120 | |
| 121 | /* Stream Source / Endpoint Descriptor */ |
| 122 | typedef struct oavx_endpoint { |
| 123 | const char *name; |
| 124 | const char *address; /* IP or hostname */ |
| 125 | uint16_t port; |
| 126 | const char *group; |
| 127 | } oavx_endpoint_t; |
| 128 | |
| 129 | /* Native Video Frame Descriptor (Planar-aware, modern media layout) */ |
| 130 | typedef struct oavx_video_frame { |
| 131 | /* Dimensions & Pixel Format */ |
| 132 | uint32_t width; |
| 133 | uint32_t height; |
| 134 | oavx_fourcc_video_type_e fourcc; |
| 135 | oavx_scan_type_t scan_type; |
| 136 | |
| 137 | /* Buffers (Planar-aware, supports packed & multi-plane formats) */ |
| 138 | uint8_t *planes[4]; |
| 139 | size_t strides[4]; |
| 140 | |
| 141 | /* Timing & Sync */ |
| 142 | oavx_rational_t framerate; |
| 143 | oavx_rational_t aspect_ratio; |
| 144 | int64_t pts_ns; /* Presentation timestamp in nanoseconds */ |
| 145 | int64_t dts_ns; /* Decode timestamp in nanoseconds */ |
| 146 | |
| 147 | /* Extended Metadata (opaque string or key-value) */ |
| 148 | const char *metadata; |
| 149 | size_t metadata_len; |
| 150 | |
| 151 | /* User / Memory Context */ |
| 152 | void *user_ctx; /* For custom buffer release callbacks */ |
| 153 | } oavx_video_frame_t; |
| 154 | |
| 155 | /* Maximum supported audio channels across OpenAVX (Pro-Audio / Dante / SDI 16-ch / 32-ch standard) */ |
| 156 | #define OAVX_MAX_AUDIO_CHANNELS 32 |
| 157 | |
| 158 | /* Standard Channel Position Bitmasks (compatible with SMPTE, Microsoft WAVEFORMATEXTENSIBLE, ALSA, CoreAudio) */ |
| 159 | typedef enum oavx_audio_channel_mask_e { |
| 160 | OAVX_AUDIO_CH_NONE = 0ULL, |
| 161 | OAVX_AUDIO_CH_FRONT_LEFT = (1ULL << 0), /* FL */ |
| 162 | OAVX_AUDIO_CH_FRONT_RIGHT = (1ULL << 1), /* FR */ |
| 163 | OAVX_AUDIO_CH_FRONT_CENTER = (1ULL << 2), /* FC / C */ |
| 164 | OAVX_AUDIO_CH_LOW_FREQUENCY = (1ULL << 3), /* LFE / Subwoofer */ |
| 165 | OAVX_AUDIO_CH_BACK_LEFT = (1ULL << 4), /* BL */ |
| 166 | OAVX_AUDIO_CH_BACK_RIGHT = (1ULL << 5), /* BR */ |
| 167 | OAVX_AUDIO_CH_FRONT_LEFT_OF_CENTER = (1ULL << 6), /* FLC */ |
| 168 | OAVX_AUDIO_CH_FRONT_RIGHT_OF_CENTER = (1ULL << 7), /* FRC */ |
| 169 | OAVX_AUDIO_CH_BACK_CENTER = (1ULL << 8), /* BC */ |
| 170 | OAVX_AUDIO_CH_SIDE_LEFT = (1ULL << 9), /* SL */ |
| 171 | OAVX_AUDIO_CH_SIDE_RIGHT = (1ULL << 10), /* SR */ |
| 172 | OAVX_AUDIO_CH_TOP_CENTER = (1ULL << 11), /* TC */ |
| 173 | OAVX_AUDIO_CH_TOP_FRONT_LEFT = (1ULL << 12), /* TFL */ |
| 174 | OAVX_AUDIO_CH_TOP_FRONT_CENTER = (1ULL << 13), /* TFC */ |
| 175 | OAVX_AUDIO_CH_TOP_FRONT_RIGHT = (1ULL << 14), /* TFR */ |
| 176 | OAVX_AUDIO_CH_TOP_BACK_LEFT = (1ULL << 15), /* TBL */ |
| 177 | OAVX_AUDIO_CH_TOP_BACK_CENTER = (1ULL << 16), /* TBC */ |
| 178 | OAVX_AUDIO_CH_TOP_BACK_RIGHT = (1ULL << 17), /* TBR */ |
| 179 | |
| 180 | /* Spatial Layout Standard Masks */ |
| 181 | OAVX_AUDIO_MASK_MONO = (OAVX_AUDIO_CH_FRONT_CENTER), |
| 182 | OAVX_AUDIO_MASK_STEREO = (OAVX_AUDIO_CH_FRONT_LEFT | OAVX_AUDIO_CH_FRONT_RIGHT), |
| 183 | OAVX_AUDIO_MASK_2_1 = (OAVX_AUDIO_CH_FRONT_LEFT | OAVX_AUDIO_CH_FRONT_RIGHT | OAVX_AUDIO_CH_LOW_FREQUENCY), |
| 184 | OAVX_AUDIO_MASK_QUAD = (OAVX_AUDIO_CH_FRONT_LEFT | OAVX_AUDIO_CH_FRONT_RIGHT | |
| 185 | OAVX_AUDIO_CH_BACK_LEFT | OAVX_AUDIO_CH_BACK_RIGHT), |
| 186 | OAVX_AUDIO_MASK_5_1 = (OAVX_AUDIO_CH_FRONT_LEFT | OAVX_AUDIO_CH_FRONT_RIGHT | |
| 187 | OAVX_AUDIO_CH_FRONT_CENTER | OAVX_AUDIO_CH_LOW_FREQUENCY | |
| 188 | OAVX_AUDIO_CH_BACK_LEFT | OAVX_AUDIO_CH_BACK_RIGHT), |
| 189 | OAVX_AUDIO_MASK_7_1 = (OAVX_AUDIO_CH_FRONT_LEFT | OAVX_AUDIO_CH_FRONT_RIGHT | |
| 190 | OAVX_AUDIO_CH_FRONT_CENTER | OAVX_AUDIO_CH_LOW_FREQUENCY | |
| 191 | OAVX_AUDIO_CH_BACK_LEFT | OAVX_AUDIO_CH_BACK_RIGHT | |
| 192 | OAVX_AUDIO_CH_SIDE_LEFT | OAVX_AUDIO_CH_SIDE_RIGHT), |
| 193 | OAVX_AUDIO_MASK_7_1_4 = (OAVX_AUDIO_MASK_7_1 | |
| 194 | OAVX_AUDIO_CH_TOP_FRONT_LEFT | OAVX_AUDIO_CH_TOP_FRONT_RIGHT | |
| 195 | OAVX_AUDIO_CH_TOP_BACK_LEFT | OAVX_AUDIO_CH_TOP_BACK_RIGHT) |
| 196 | } oavx_audio_channel_mask_e; |
| 197 | |
| 198 | typedef uint64_t oavx_audio_channel_mask_t; |
| 199 | |
| 200 | /* Discrete Broadcast Tracks (bit 32..63: generic independent tracks 1..32) */ |
| 201 | #define OAVX_AUDIO_MASK_DISCRETE (1ULL << 32) |
| 202 | #define OAVX_AUDIO_CH_DISCRETE_TRACK(n) (((n) >= 1 && (n) <= 32) ? (1ULL << (31 + (n))) : 0ULL) |
| 203 | |
| 204 | /* Native Audio Frame Descriptor */ |
| 205 | typedef struct oavx_audio_frame { |
| 206 | uint32_t sample_rate; |
| 207 | uint16_t channels; |
| 208 | uint32_t frames; /* Number of sample frames per channel */ |
| 209 | oavx_audio_format_t format; |
| 210 | |
| 211 | /* Audio buffer pointers (planes[0..ch-1] for planar, planes[0] for interleaved) */ |
| 212 | void *planes[OAVX_MAX_AUDIO_CHANNELS]; |
| 213 | size_t stride_bytes; |
| 214 | |
| 215 | int64_t pts_ns; |
| 216 | uint64_t channel_mask; /* Spatial speaker mask (oavx_audio_channel_mask_t) or 0 for default */ |
| 217 | const char *metadata; |
| 218 | size_t metadata_len; |
| 219 | void *user_ctx; |
| 220 | } oavx_audio_frame_t; |
| 221 | |
| 222 | /* Interleaved Audio Format Descriptors */ |
| 223 | typedef struct oavx_audio_frame_interleaved_16s_t { |
| 224 | uint32_t sample_rate; |
| 225 | uint16_t channels; |
| 226 | uint32_t frames; |
| 227 | int64_t pts_ns; |
| 228 | int64_t reference_level; |
| 229 | int16_t *data; |
| 230 | } oavx_audio_frame_interleaved_16s_t; |
| 231 | |
| 232 | typedef struct oavx_audio_frame_interleaved_32f_t { |
| 233 | uint32_t sample_rate; |
| 234 | uint16_t channels; |
| 235 | uint32_t frames; |
| 236 | int64_t pts_ns; |
| 237 | float *data; |
| 238 | } oavx_audio_frame_interleaved_32f_t; |
| 239 | |
| 240 | typedef struct oavx_audio_frame_interleaved_32s_t { |
| 241 | uint32_t sample_rate; |
| 242 | uint16_t channels; |
| 243 | uint32_t frames; |
| 244 | int64_t pts_ns; |
| 245 | int32_t *data; |
| 246 | } oavx_audio_frame_interleaved_32s_t; |
| 247 | |
| 248 | /* Metadata Frame Descriptor */ |
| 249 | typedef struct oavx_metadata_frame { |
| 250 | size_t length; |
| 251 | int64_t pts_ns; |
| 252 | char *data; |
| 253 | } oavx_metadata_frame_t; |
| 254 | |
| 255 | /* Tally Status Flags & Descriptor */ |
| 256 | typedef enum oavx_tally_flags { |
| 257 | OAVX_TALLY_NONE = 0, |
| 258 | OAVX_TALLY_PROGRAM = (1 << 0), |
| 259 | OAVX_TALLY_PREVIEW = (1 << 1), |
| 260 | OAVX_TALLY_RECORDING = (1 << 2) |
| 261 | } oavx_tally_flags_t; |
| 262 | |
| 263 | typedef struct oavx_tally { |
| 264 | uint32_t flags; /* Bitmask of oavx_tally_flags_t */ |
| 265 | } oavx_tally_t; |
| 266 | |
| 267 | /* Modern Color Format & Bandwidth Profiles */ |
| 268 | typedef enum oavx_color_format_e { |
| 269 | OAVX_COLOR_FORMAT_BGRX_BGRA = 0, |
| 270 | OAVX_COLOR_FORMAT_UYVY_BGRA = 1, |
| 271 | OAVX_COLOR_FORMAT_RGBX_RGBA = 2, |
| 272 | OAVX_COLOR_FORMAT_UYVY_RGBA = 3, |
| 273 | OAVX_COLOR_FORMAT_FASTEST = 4, |
| 274 | OAVX_COLOR_FORMAT_BEST = 5, |
| 275 | OAVX_COLOR_FORMAT_COMPRESSED_V1 = 6, |
| 276 | OAVX_COLOR_FORMAT_P216 = 7, |
| 277 | OAVX_COLOR_FORMAT_COUNT = 8 |
| 278 | } oavx_color_format_e; |
| 279 | |
| 280 | typedef enum oavx_bandwidth_e { |
| 281 | OAVX_BANDWIDTH_METADATA_ONLY = 0, |
| 282 | OAVX_BANDWIDTH_AUDIO_ONLY = 1, |
| 283 | OAVX_BANDWIDTH_LOWEST = 2, |
| 284 | OAVX_BANDWIDTH_HIGHEST = 3, |
| 285 | OAVX_BANDWIDTH_COUNT = 4 |
| 286 | } oavx_bandwidth_e; |
| 287 | |
| 288 | typedef enum oavx_transport_e { |
| 289 | OAVX_TRANSPORT_TCP = 0, /* Default reliable stream transport (TCP) */ |
| 290 | OAVX_TRANSPORT_RUDP = 1, /* Reliable UDP with Selective NACK retransmission */ |
| 291 | OAVX_TRANSPORT_UDP = 2 /* Unicast/Multicast raw datagram transport */ |
| 292 | } oavx_transport_e; |
| 293 | |
| 294 | /* Performance & Queue Telemetry */ |
| 295 | typedef struct oavx_performance_t { |
| 296 | int64_t video_frames; |
| 297 | int64_t audio_frames; |
| 298 | int64_t metadata_frames; |
| 299 | } oavx_performance_t; |
| 300 | |
| 301 | typedef struct oavx_queue_t { |
| 302 | int video_frames; |
| 303 | int audio_frames; |
| 304 | int metadata_frames; |
| 305 | } oavx_queue_t; |
| 306 | |
| 307 | /* Comprehensive Stream Observability & Real-Time Telemetry */ |
| 308 | typedef struct oavx_telemetry_t { |
| 309 | /* 1. Media Pipeline Metrics */ |
| 310 | int64_t video_frames_total; /* Total video frames delivered */ |
| 311 | int64_t audio_frames_total; /* Total audio frames delivered */ |
| 312 | int64_t metadata_frames_total; /* Total metadata frames delivered */ |
| 313 | int64_t dropped_frames_total; /* Total frames dropped */ |
| 314 | float fps; /* Instantaneous delivered video frames per second */ |
| 315 | |
| 316 | /* 2. Transport Dynamics */ |
| 317 | float bitrate_mbps; /* Instantaneous wire throughput in megabits/second */ |
| 318 | uint64_t total_wire_bytes; /* Total payload + protocol bytes transferred */ |
| 319 | float inter_frame_jitter_ms; /* Inter-frame arrival time variance (EMA, in ms) */ |
| 320 | |
| 321 | /* 3. OS Kernel & Socket Diagnostics */ |
| 322 | float kernel_rtt_ms; /* Kernel TCP Round-Trip Time in milliseconds (from TCP_INFO) */ |
| 323 | uint32_t tcp_retransmissions; /* Cumulative TCP packet retransmissions */ |
| 324 | uint32_t socket_send_q_bytes; /* Outgoing unacknowledged bytes in kernel send queue (SIOCOUTQ) */ |
| 325 | uint32_t socket_recv_q_bytes; /* Incoming unread bytes in kernel receive queue (FIONREAD) */ |
| 326 | uint32_t congestion_level; /* Dynamic link congestion: 0=Normal (60fps), 1=Moderate (30fps), 2=Severe (15fps) */ |
| 327 | |
| 328 | /* 4. Stream & Format Attributes */ |
| 329 | char remote_endpoint[128]; /* IP:Port of remote peer */ |
| 330 | uint32_t fourcc; /* Video FourCC codec/format (e.g., UYVY, P216, SHQ0) */ |
| 331 | uint32_t width; /* Video width in pixels */ |
| 332 | uint32_t height; /* Video height in pixels */ |
| 333 | bool is_connected; /* Active connection state */ |
| 334 | } oavx_telemetry_t; |
| 335 | |
| 336 | /* ========================================================================= */ |
| 337 | /* OpenAVX Standard Status & Error Codes */ |
| 338 | /* ========================================================================= */ |
| 339 | typedef enum oavx_status { |
| 340 | OAVX_SUCCESS = 0, /* Operation completed successfully */ |
| 341 | OAVX_ERR_GENERIC = -1, /* General or unspecified runtime error */ |
| 342 | OAVX_ERR_INVALID_ARG = -2, /* Null pointer or invalid parameter passed */ |
| 343 | OAVX_ERR_TIMEOUT = -3, /* Operation timed out before completion */ |
| 344 | OAVX_ERR_NOT_CONNECTED = -4, /* Network socket is not connected or remote closed */ |
| 345 | OAVX_ERR_QUEUE_FULL = -5, /* Pipeline queue capacity reached; frame dropped */ |
| 346 | OAVX_ERR_UNSUPPORTED = -6, /* Requested format, codec, or feature is unsupported */ |
| 347 | OAVX_ERR_WOULD_BLOCK = -7 /* Non-blocking transport would block (EAGAIN/EWOULDBLOCK) */ |
| 348 | } oavx_status_t; |
| 349 | |
| 350 | OPENAVX_API const char* oavx_status_to_string(oavx_status_t status); |
| 351 | |
| 352 | /* ========================================================================= */ |
| 353 | /* OpenAVX Native Unified Media Transport API (oavx_*) */ |
| 354 | /* Native, high-performance, stream-oriented media pipeline interface */ |
| 355 | /* ========================================================================= */ |
| 356 | |
| 357 | typedef struct oavx_context oavx_context_t; |
| 358 | typedef struct oavx_stream oavx_stream_t; |
| 359 | typedef struct oavx_discovery oavx_discovery_t; |
| 360 | |
| 361 | /* Stream Direction */ |
| 362 | typedef enum oavx_direction { |
| 363 | OAVX_DIR_TRANSMIT = 1, |
| 364 | OAVX_DIR_RECEIVE = 2 |
| 365 | } oavx_direction_t; |
| 366 | |
| 367 | /* Wire Framing Profile Descriptor (for profile-based wire transport) */ |
| 368 | #ifndef OAVX_WIRE_PROFILE_DEFINED |
| 369 | #define OAVX_WIRE_PROFILE_DEFINED |
| 370 | typedef struct oavx_wire_profile { |
| 371 | uint32_t magic_video; |
| 372 | uint32_t magic_audio; |
| 373 | uint32_t magic_metadata; |
| 374 | uint32_t magic_udp; |
| 375 | uint32_t compat_magic_video; |
| 376 | uint32_t compat_magic_audio; |
| 377 | uint32_t compat_magic_metadata; |
| 378 | uint32_t compat_magic_udp; |
| 379 | uint16_t base_port; |
| 380 | const char* mdns_service; |
| 381 | const char* handshake_tag; |
| 382 | const char* tally_tag; |
| 383 | const char* color_info_tag; |
| 384 | const char* ptz_tag; |
| 385 | const char* record_tag; |
| 386 | } oavx_wire_profile_t; |
| 387 | #endif |
| 388 | |
| 389 | /* Stream Configuration */ |
| 390 | typedef struct oavx_stream_config { |
| 391 | const char *name; /* Stream name (e.g. "STUDIO_CAM_1") */ |
| 392 | const char *endpoint; /* Remote IP:Port or URL (for receiver) */ |
| 393 | oavx_direction_t direction; /* TRANSMIT or RECEIVE */ |
| 394 | oavx_color_format_e color_format; /* Preferred color format */ |
| 395 | oavx_bandwidth_e bandwidth; /* Bandwidth profile */ |
| 396 | bool clock_sync; /* Pacing and clock sync */ |
| 397 | const char *groups; /* Announcement / Finder groups */ |
| 398 | const oavx_wire_profile_t *wire_profile; /* Optional custom wire profile override (NULL = context default) */ |
| 399 | uint32_t max_connections; /* Max simultaneous client connections (0 = default 32, max 64) */ |
| 400 | const char *bind_ip; /* Explicit local IP or NIC interface to bind (e.g. "10.0.0.50" or "eth1", NULL = auto) */ |
| 401 | oavx_transport_e transport; /* Transport protocol: TCP (default) or RUDP */ |
| 402 | uint32_t video_codec_fourcc; /* Target compressed video FourCC (0 = raw/pass-through, or OAVX_FOURCC_VIDEO_TYPE_H264 / HEVC / SpeedHQ) */ |
| 403 | uint32_t video_bitrate_kbps; /* Target video bitrate in kbps (0 = automatic default) */ |
| 404 | uint32_t keyframe_interval; /* Keyframe interval in frames (0 = default 60 frames) */ |
| 405 | const char *passphrase; /* Optional passphrase for native E2EE (ChaCha20-Poly1305, NULL = plaintext) */ |
| 406 | } oavx_stream_config_t; |
| 407 | |
| 408 | /* Device PTZ Camera State Descriptor */ |
| 409 | typedef struct oavx_ptz_state { |
| 410 | float pan; |
| 411 | float tilt; |
| 412 | float zoom; |
| 413 | float focus; |
| 414 | } oavx_ptz_state_t; |
| 415 | |
| 416 | /* Context Lifecycle */ |
| 417 | /** |
| 418 | * Creates an OpenAVX engine context and initializes networking and SIMD dispatch. |
| 419 | * Reference-counted; returns existing instance if already initialized. |
| 420 | * |
| 421 | * @return Context pointer, or NULL on allocation/socket failure. |
| 422 | */ |
| 423 | OPENAVX_API oavx_context_t* oavx_context_create(void); |
| 424 | OPENAVX_API void oavx_context_destroy(oavx_context_t *ctx); |
| 425 | OPENAVX_API const char* oavx_version(void); |
| 426 | OPENAVX_API bool oavx_is_supported_cpu(void); |
| 427 | |
| 428 | /** |
| 429 | * Overrides wire protocol magic tags and ports for the context and process. |
| 430 | * Pass NULL to restore default OpenAVX protocol signatures. |
| 431 | */ |
| 432 | OPENAVX_API void oavx_context_set_wire_profile(oavx_context_t *ctx, const oavx_wire_profile_t *profile); |
| 433 | OPENAVX_API void oavx_context_get_wire_profile(oavx_context_t *ctx, oavx_wire_profile_t *out_profile); |
| 434 | |
| 435 | /* Unified Stream Lifecycle */ |
| 436 | /** |
| 437 | * Opens a streaming session (transmitter or receiver) with background I/O threads. |
| 438 | * |
| 439 | * @param ctx Active library context. |
| 440 | * @param config Session parameters (name, direction, IP/port, codecs, encryption). |
| 441 | * @return Stream handle, or NULL on connection/binding failure. |
| 442 | */ |
| 443 | OPENAVX_API oavx_stream_t* oavx_stream_open(oavx_context_t *ctx, const oavx_stream_config_t *config); |
| 444 | OPENAVX_API void oavx_stream_close(oavx_stream_t *stream); |
| 445 | |
| 446 | /* Stream Data Transmission */ |
| 447 | /** |
| 448 | * Submits an uncompressed or compressed video frame to connected receivers. |
| 449 | * Non-blocking; drops frame if client transmission queues are saturated. |
| 450 | * Caller retains ownership of frame and memory planes. |
| 451 | */ |
| 452 | OPENAVX_API oavx_status_t oavx_stream_send_video(oavx_stream_t *stream, const oavx_video_frame_t *frame); |
| 453 | |
| 454 | /** |
| 455 | * Submits an audio frame (planar float or interleaved PCM). |
| 456 | * Caller retains ownership of audio buffers. |
| 457 | */ |
| 458 | OPENAVX_API oavx_status_t oavx_stream_send_audio(oavx_stream_t *stream, const oavx_audio_frame_t *frame); |
| 459 | OPENAVX_API oavx_status_t oavx_stream_send_metadata(oavx_stream_t *stream, const oavx_metadata_frame_t *meta); |
| 460 | |
| 461 | /** |
| 462 | * Configures audio encoding mode (0=uncompressed float, 1=Opus/ADPCM, 2=adaptive LAN/WAN). |
| 463 | */ |
| 464 | OPENAVX_API oavx_status_t oavx_stream_set_audio_compression(oavx_stream_t *stream, oavx_audio_compression_mode_e mode, int target_bitrate_kbps); |
| 465 | |
| 466 | /** |
| 467 | * Sets runtime video compression (e.g. SpeedHQ, H.264, or HEVC) and target bitrate. |
| 468 | * Pass 0 to restore raw uncompressed pass-through. |
| 469 | */ |
| 470 | OPENAVX_API oavx_status_t oavx_stream_set_video_compression(oavx_stream_t *stream, uint32_t target_fourcc, uint32_t bitrate_kbps); |
| 471 | OPENAVX_API uint32_t oavx_stream_get_video_compression(oavx_stream_t *stream); |
| 472 | OPENAVX_API oavx_status_t oavx_stream_set_video_quality(oavx_stream_t *stream, uint8_t quality); |
| 473 | OPENAVX_API uint8_t oavx_stream_get_video_quality(oavx_stream_t *stream); |
| 474 | |
| 475 | /** |
| 476 | * Starts an embedded RTSP 1.0 streaming server on this transmitter stream. |
| 477 | */ |
| 478 | OPENAVX_API oavx_status_t oavx_stream_enable_rtsp_server(oavx_stream_t *stream, uint16_t port, const char *path); |
| 479 | OPENAVX_API void oavx_stream_disable_rtsp_server(oavx_stream_t *stream); |
| 480 | OPENAVX_API uint16_t oavx_stream_get_rtsp_port(oavx_stream_t *stream); |
| 481 | OPENAVX_API int oavx_stream_get_rtsp_client_count(oavx_stream_t *stream); |
| 482 | |
| 483 | /* Embedded HTTP / fMP4 Low-Latency Web Preview */ |
| 484 | /** |
| 485 | * Starts an embedded HTTP/fMP4 web preview server for zero-plugin browser playback. |
| 486 | */ |
| 487 | OPENAVX_API oavx_status_t oavx_stream_enable_web_preview(oavx_stream_t *stream, uint16_t port); |
| 488 | OPENAVX_API void oavx_stream_disable_web_preview(oavx_stream_t *stream); |
| 489 | OPENAVX_API uint16_t oavx_stream_get_web_preview_port(oavx_stream_t *stream); |
| 490 | OPENAVX_API const char* oavx_stream_get_web_preview_url(oavx_stream_t *stream, char *out_url, size_t max_len); |
| 491 | OPENAVX_API int oavx_stream_get_web_client_count(oavx_stream_t *stream); |
| 492 | |
| 493 | /* Stream Data Reception */ |
| 494 | /** |
| 495 | * Fetches the next available frame from the receive queue. |
| 496 | * Populates only the descriptor corresponding to the returned frame type. |
| 497 | * |
| 498 | * @param timeout_ms Max milliseconds to wait (0 = non-blocking poll). |
| 499 | * @return Received frame type (VIDEO, AUDIO, METADATA), or NONE on timeout. |
| 500 | * @note Call oavx_stream_release_video() after processing a returned video frame. |
| 501 | */ |
| 502 | OPENAVX_API oavx_frame_type_t oavx_stream_receive( |
| 503 | oavx_stream_t *stream, |
| 504 | oavx_video_frame_t *v, |
| 505 | oavx_audio_frame_t *a, |
| 506 | oavx_metadata_frame_t *m, |
| 507 | uint32_t timeout_ms); |
| 508 | |
| 509 | /** |
| 510 | * Releases internal buffer hold on a video frame returned by oavx_stream_receive(). |
| 511 | */ |
| 512 | OPENAVX_API void oavx_stream_release_video(oavx_stream_t *stream, const oavx_video_frame_t *frame); |
| 513 | OPENAVX_API void oavx_stream_release_audio(oavx_stream_t *stream, const oavx_audio_frame_t *frame); |
| 514 | OPENAVX_API void oavx_stream_release_metadata(oavx_stream_t *stream, const oavx_metadata_frame_t *meta); |
| 515 | |
| 516 | /* Stream Device & Camera Controls */ |
| 517 | OPENAVX_API bool oavx_stream_set_ptz(oavx_stream_t *stream, const oavx_ptz_state_t *ptz); |
| 518 | OPENAVX_API bool oavx_stream_set_tally(oavx_stream_t *stream, const oavx_tally_t *tally); |
| 519 | OPENAVX_API bool oavx_stream_get_tally(oavx_stream_t *stream, oavx_tally_t *out_tally, uint32_t timeout_ms); |
| 520 | OPENAVX_API bool oavx_stream_record_trigger(oavx_stream_t *stream, const char *action, const char *filename_hint); |
| 521 | OPENAVX_API bool oavx_stream_record_status(oavx_stream_t *stream, bool *is_recording, const char **filename, const char **error); |
| 522 | OPENAVX_API bool oavx_stream_record_set_audio_level(oavx_stream_t *stream, float level_db); |
| 523 | |
| 524 | /* Network Discovery Grid */ |
| 525 | /** |
| 526 | * Spawns an mDNS background discovery scanner for active OpenAVX sources. |
| 527 | * |
| 528 | * @param groups Comma-separated discovery groups, or NULL for default ("public"). |
| 529 | */ |
| 530 | OPENAVX_API oavx_discovery_t* oavx_discovery_create(oavx_context_t *ctx, const char *groups); |
| 531 | OPENAVX_API void oavx_discovery_destroy(oavx_discovery_t *disc); |
| 532 | |
| 533 | /** |
| 534 | * Copies currently discovered endpoints into caller-provided array. |
| 535 | * |
| 536 | * @return Number of endpoints written (<= max_count). |
| 537 | */ |
| 538 | OPENAVX_API size_t oavx_discovery_get_sources(oavx_discovery_t *disc, oavx_endpoint_t *out_sources, size_t max_count); |
| 539 | |
| 540 | /** |
| 541 | * Blocks until the discovered source list changes or timeout expires. |
| 542 | */ |
| 543 | OPENAVX_API bool oavx_discovery_wait(oavx_discovery_t *disc, uint32_t timeout_ms); |
| 544 | |
| 545 | /* Stream Connection & Advanced Endpoint Controls */ |
| 546 | /** |
| 547 | * Connects receiver to a remote stream endpoint. |
| 548 | */ |
| 549 | OPENAVX_API void oavx_stream_connect(oavx_stream_t *stream, const oavx_endpoint_t *endpoint); |
| 550 | OPENAVX_API const oavx_endpoint_t* oavx_stream_get_endpoint(oavx_stream_t *stream); |
| 551 | OPENAVX_API oavx_frame_type_t oavx_stream_capture_metadata(oavx_stream_t *stream, oavx_metadata_frame_t *meta, uint32_t timeout_ms); |
| 552 | OPENAVX_API void oavx_stream_clear_connection_metadata(oavx_stream_t *stream); |
| 553 | OPENAVX_API void oavx_stream_add_connection_metadata(oavx_stream_t *stream, const oavx_metadata_frame_t *meta); |
| 554 | |
| 555 | /** |
| 556 | * Configures backup failover endpoint if primary stream stops receiving frames. |
| 557 | */ |
| 558 | OPENAVX_API void oavx_stream_set_failover(oavx_stream_t *stream, const oavx_endpoint_t *failover_endpoint); |
| 559 | OPENAVX_API bool oavx_stream_is_on_failover(oavx_stream_t *stream); |
| 560 | OPENAVX_API void oavx_stream_set_failover_timeout(oavx_stream_t *stream, uint32_t timeout_ms); |
| 561 | OPENAVX_API void oavx_stream_set_auto_revert(oavx_stream_t *stream, bool auto_revert, uint32_t hold_time_ms); |
| 562 | OPENAVX_API int oavx_stream_get_connection_count(oavx_stream_t *stream, uint32_t timeout_ms); |
| 563 | OPENAVX_API bool oavx_stream_get_performance(oavx_stream_t *stream, oavx_performance_t *total, oavx_performance_t *dropped); |
| 564 | OPENAVX_API bool oavx_stream_get_queue(oavx_stream_t *stream, oavx_queue_t *total); |
| 565 | OPENAVX_API bool oavx_stream_get_telemetry(oavx_stream_t *stream, oavx_telemetry_t *out_telemetry); |
| 566 | OPENAVX_API size_t oavx_telemetry_to_json(const oavx_telemetry_t *telemetry, char *out_json, size_t max_len); |
| 567 | OPENAVX_API const char* oavx_stream_get_web_control(oavx_stream_t *stream); |
| 568 | |
| 569 | /* SpeedHQ Dynamic Quantization & Bitrate Control */ |
| 570 | OPENAVX_API void oavx_speedhq_set_quality(uint8_t quality); |
| 571 | OPENAVX_API uint8_t oavx_speedhq_get_quality(void); |
| 572 | |
| 573 | /* Async Socket & Event-Loop Integration */ |
| 574 | OPENAVX_API int oavx_stream_get_fd(oavx_stream_t *stream); |
| 575 | OPENAVX_API int oavx_discovery_get_fd(oavx_discovery_t *disc); |
| 576 | |
| 577 | /* Dynamic Virtual Matrix Router */ |
| 578 | typedef struct oavx_router oavx_router_t; |
| 579 | OPENAVX_API oavx_router_t* oavx_router_create(oavx_context_t *ctx, const char *name, const char *groups); |
| 580 | OPENAVX_API void oavx_router_destroy(oavx_router_t *router); |
| 581 | |
| 582 | /** |
| 583 | * Dynamically switches router output to a new upstream source without dropping downstream client connections. |
| 584 | */ |
| 585 | OPENAVX_API bool oavx_router_route(oavx_router_t *router, const oavx_endpoint_t *source); |
| 586 | OPENAVX_API bool oavx_router_clear(oavx_router_t *router); |
| 587 | OPENAVX_API oavx_endpoint_t oavx_router_get_source(oavx_router_t *router); |
| 588 | |
| 589 | /* Media Clock & Frame Synchronizer */ |
| 590 | typedef struct oavx_framesync oavx_framesync_t; |
| 591 | OPENAVX_API oavx_framesync_t* oavx_framesync_create(oavx_stream_t *stream); |
| 592 | OPENAVX_API void oavx_framesync_destroy(oavx_framesync_t *fs); |
| 593 | |
| 594 | /** |
| 595 | * Pulls the freshest video frame from the stream clock, repeating prior frame on underrun. |
| 596 | * Call oavx_framesync_free_video() after consuming the frame. |
| 597 | */ |
| 598 | OPENAVX_API void oavx_framesync_capture_video(oavx_framesync_t *fs, oavx_video_frame_t *frame, int field_type); |
| 599 | OPENAVX_API void oavx_framesync_free_video(oavx_framesync_t *fs, oavx_video_frame_t *frame); |
| 600 | OPENAVX_API void oavx_framesync_capture_audio(oavx_framesync_t *fs, oavx_audio_frame_t *frame, uint32_t sample_rate, uint16_t channels, uint32_t num_samples); |
| 601 | OPENAVX_API void oavx_framesync_free_audio(oavx_framesync_t *fs, oavx_audio_frame_t *frame); |
| 602 | OPENAVX_API int oavx_framesync_audio_queue_depth(oavx_framesync_t *fs); |
| 603 | |
| 604 | /* Unified Media Utilities */ |
| 605 | OPENAVX_API void oavx_util_audio_to_interleaved_16s(const oavx_audio_frame_t* src, oavx_audio_frame_interleaved_16s_t* dst); |
| 606 | OPENAVX_API void oavx_util_audio_from_interleaved_16s(const oavx_audio_frame_interleaved_16s_t* src, oavx_audio_frame_t* dst); |
| 607 | OPENAVX_API void oavx_util_audio_to_interleaved_32f(const oavx_audio_frame_t* src, oavx_audio_frame_interleaved_32f_t* dst); |
| 608 | OPENAVX_API void oavx_util_audio_from_interleaved_32f(const oavx_audio_frame_interleaved_32f_t* src, oavx_audio_frame_t* dst); |
| 609 | OPENAVX_API void oavx_util_audio_to_interleaved_32s(const oavx_audio_frame_t* src, oavx_audio_frame_interleaved_32s_t* dst); |
| 610 | OPENAVX_API void oavx_util_audio_from_interleaved_32s(const oavx_audio_frame_interleaved_32s_t* src, oavx_audio_frame_t* dst); |
| 611 | |
| 612 | /** |
| 613 | * Unpacks SMPTE 292M 10-bit V210 video into planar 16-bit P216 (and reverse). |
| 614 | */ |
| 615 | OPENAVX_API void oavx_util_V210_to_P216(const oavx_video_frame_t* src, oavx_video_frame_t* dst); |
| 616 | OPENAVX_API void oavx_util_P216_to_V210(const oavx_video_frame_t* src, oavx_video_frame_t* dst); |
| 617 | |
| 618 | /* Library Logging & Diagnostics */ |
| 619 | typedef enum oavx_log_level_e { |
| 620 | OAVX_LOG_QUIET = 0, |
| 621 | OAVX_LOG_ERROR = 1, |
| 622 | OAVX_LOG_WARN = 2, |
| 623 | OAVX_LOG_INFO = 3, |
| 624 | OAVX_LOG_DEBUG = 4 |
| 625 | } oavx_log_level_e; |
| 626 | |
| 627 | typedef void (*oavx_log_callback_t)(oavx_log_level_e level, const char *module, const char *message, void *user_ctx); |
| 628 | |
| 629 | OPENAVX_API void oavx_set_log_level(oavx_log_level_e level); |
| 630 | OPENAVX_API oavx_log_level_e oavx_get_log_level(void); |
| 631 | OPENAVX_API void oavx_set_log_callback(oavx_log_callback_t cb, void *user_ctx); |
| 632 | OPENAVX_API void oavx_log_write(oavx_log_level_e level, const char *module, const char *fmt, ...); |
| 633 | |
| 634 | #ifdef __cplusplus |
| 635 | } |
| 636 | #endif |
| 637 | |
| 638 | #endif /* OPENAVX_H */ |