+ +
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/avx_rate_control.h - Adaptive Bitrate & Dynamic FEC Controller (GCC / BBR Hybrid) |
| 7 | */ |
| 8 | |
| 9 | #ifndef AVX_RATE_CONTROL_H |
| 10 | #define AVX_RATE_CONTROL_H |
| 11 | |
| 12 | #include <stdint.h> |
| 13 | #include <stdbool.h> |
| 14 | #include <stddef.h> |
| 15 | |
| 16 | #include "openavx.h" |
| 17 | #include "avx_platform.h" |
| 18 | #include "avx_fec.h" |
| 19 | #include "avx_udp.h" |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | typedef enum { |
| 26 | AVX_WAN_CONG_NORMAL = 0, /* Network clear: nominal queuing delay and low packet loss */ |
| 27 | AVX_WAN_CONG_PRESSURE = 1, /* Queuing delay rising towards buffer limit */ |
| 28 | AVX_WAN_CONG_OVERUSE = 2 /* Bottleneck saturated: severe queuing delay or packet loss */ |
| 29 | } avx_wan_congestion_state_t; |
| 30 | |
| 31 | typedef struct { |
| 32 | uint32_t min_bitrate_bps; /* Minimum allowable bitrate (default: 2,000,000 = 2 Mbps) */ |
| 33 | uint32_t max_bitrate_bps; /* Maximum allowable bitrate (default: 150,000,000 = 150 Mbps) */ |
| 34 | uint32_t start_bitrate_bps; /* Initial starting bitrate (default: 50,000,000 = 50 Mbps) */ |
| 35 | float target_fps; /* Target framerate (default: 60.0f) */ |
| 36 | uint8_t min_quality; /* Lowest SpeedHQ quality level (default: 30) */ |
| 37 | uint8_t max_quality; /* Highest SpeedHQ quality level (default: 96) */ |
| 38 | bool fec_auto_tune; /* Automatically tune FEC matrix density (default: true) */ |
| 39 | } avx_rate_controller_config_t; |
| 40 | |
| 41 | typedef struct avx_rate_controller_t avx_rate_controller_t; |
| 42 | |
| 43 | /** |
| 44 | * Creates an Adaptive Bitrate & FEC Controller instance. |
| 45 | * If cfg is NULL, recommended defaults are applied. |
| 46 | */ |
| 47 | OPENAVX_API avx_rate_controller_t* avx_rate_controller_create(const avx_rate_controller_config_t* cfg); |
| 48 | |
| 49 | /** |
| 50 | * Destroys the rate controller instance and releases resources. |
| 51 | */ |
| 52 | OPENAVX_API void avx_rate_controller_destroy(avx_rate_controller_t* c); |
| 53 | |
| 54 | /** |
| 55 | * Resets controller internal state (filters, minimum RTT, and telemetry history). |
| 56 | */ |
| 57 | OPENAVX_API void avx_rate_controller_reset(avx_rate_controller_t* c); |
| 58 | |
| 59 | /** |
| 60 | * Ingests live RUDP telemetry and updates the congestion model, target bitrate, |
| 61 | * recommended SpeedHQ quality, and FEC matrix density. |
| 62 | * |
| 63 | * @param c Rate controller instance. |
| 64 | * @param telem Pointer to current RUDP telemetry snapshot. |
| 65 | * @param now_ms Monotonic timestamp in milliseconds. |
| 66 | */ |
| 67 | OPENAVX_API void avx_rate_controller_update_telemetry( |
| 68 | avx_rate_controller_t* c, |
| 69 | const avx_rudp_telemetry_t* telem, |
| 70 | int64_t now_ms |
| 71 | ); |
| 72 | |
| 73 | /** |
| 74 | * Retrieves the recommended video bitrate target in bits per second. |
| 75 | */ |
| 76 | OPENAVX_API uint32_t avx_rate_controller_get_target_bitrate(const avx_rate_controller_t* c); |
| 77 | |
| 78 | /** |
| 79 | * Retrieves the recommended SpeedHQ quality level (range: min_quality .. max_quality). |
| 80 | */ |
| 81 | OPENAVX_API uint8_t avx_rate_controller_get_quality(const avx_rate_controller_t* c); |
| 82 | |
| 83 | /** |
| 84 | * Retrieves the dynamically tuned FEC matrix configuration. |
| 85 | */ |
| 86 | OPENAVX_API void avx_rate_controller_get_fec_config(const avx_rate_controller_t* c, avx_fec_config_t* out_fec); |
| 87 | |
| 88 | /** |
| 89 | * Retrieves the recommended temporal decimation cadence (1 = full fps, 2 = half fps, etc.). |
| 90 | */ |
| 91 | OPENAVX_API uint32_t avx_rate_controller_get_cadence(const avx_rate_controller_t* c); |
| 92 | |
| 93 | /** |
| 94 | * Retrieves the current WAN congestion assessment state. |
| 95 | */ |
| 96 | OPENAVX_API avx_wan_congestion_state_t avx_rate_controller_get_congestion_state(const avx_rate_controller_t* c); |
| 97 | |
| 98 | /** |
| 99 | * Applies the current dynamically tuned FEC parameters directly to an RUDP sender session. |
| 100 | */ |
| 101 | OPENAVX_API void avx_rate_controller_apply_to_sender(const avx_rate_controller_t* c, avx_udp_rudp_sender_t* s); |
| 102 | |
| 103 | #ifdef __cplusplus |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | #endif /* AVX_RATE_CONTROL_H */ |