libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-adapt.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

LWS_VISIBLE LWS_EXTERN struct lws_adapt * lws_adapt_create (int num_levels, uint32_t ewma_halflife_short_us, uint32_t ewma_halflife_long_us)
 
LWS_VISIBLE LWS_EXTERN void lws_adapt_destroy (struct lws_adapt **padapt)
 
LWS_VISIBLE LWS_EXTERN void lws_adapt_report (struct lws_adapt *adapt, int success, lws_usec_t us)
 
LWS_VISIBLE LWS_EXTERN void lws_adapt_report_val (struct lws_adapt *adapt, uint64_t val, lws_usec_t us)
 
LWS_VISIBLE LWS_EXTERN int lws_adapt_get_level (struct lws_adapt *adapt)
 
LWS_VISIBLE LWS_EXTERN uint64_t lws_adapt_get_val (struct lws_adapt *adapt, int level, int is_short)
 

Function Documentation

◆ lws_adapt_create()

LWS_VISIBLE LWS_EXTERN struct lws_adapt * lws_adapt_create ( int num_levels,
uint32_t ewma_halflife_short_us,
uint32_t ewma_halflife_long_us )

lws_adapt_create() - Create an adaptive performance tracking context

Parameters
num_levelsThe number of discrete capability levels (0=Best, num_levels-1=Safest)
ewma_halflife_short_usHalf-life decay for short-term reaction (e.g. 5 seconds)
ewma_halflife_long_usHalf-life decay for long-term recovery (e.g. 60 seconds)

Returns an opaque tracking object. Level 0 is considered the highest quality but most-demanding state. Level N is the safest fallback.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_adapt_destroy()

LWS_VISIBLE LWS_EXTERN void lws_adapt_destroy ( struct lws_adapt ** padapt)

lws_adapt_destroy() - Destroy the adaptation tracking context

Parameters
padaptPointer to the adapt context pointer.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_adapt_report()

LWS_VISIBLE LWS_EXTERN void lws_adapt_report ( struct lws_adapt * adapt,
int success,
lws_usec_t us )

lws_adapt_report() - Report success or failure of the current capability cycle

Parameters
adaptThe adaptation context
success0 if the system failed to meet constraints (lag, frame drop), 1 if it met them
usCurrent timestamp in microseconds (e.g. from lws_now_usecs())

Records a data point. The underlying EWMAs will decay older points based on the elapsed time since the previous report.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_adapt_report_val()

LWS_VISIBLE LWS_EXTERN void lws_adapt_report_val ( struct lws_adapt * adapt,
uint64_t val,
lws_usec_t us )

lws_adapt_report_val() - Report an arbitrary value tracker for the current capability cycle

Parameters
adaptThe adaptation context
valThe arbitrary value to track via EWMA (e.g., ping duration)
usCurrent timestamp in microseconds (e.g. from lws_now_usecs())

Records a data point tracking an arbitrary value.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_adapt_get_level()

LWS_VISIBLE LWS_EXTERN int lws_adapt_get_level ( struct lws_adapt * adapt)

lws_adapt_get_level() - Query the recommended capability tier

Parameters
adaptThe adaptation context

Returns the currently recommended level integer (0 ... num_levels-1). If the short-term EWMA falls below a drop threshold, it immediately degrades the recommended internal level. If both the short-term and long-term EWMAs for the lower level are highly stable and the exponential backoff from any previous failure has expired, it recommends an upgrade.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_adapt_get_val()

LWS_VISIBLE LWS_EXTERN uint64_t lws_adapt_get_val ( struct lws_adapt * adapt,
int level,
int is_short )

lws_adapt_get_val() - Query the EWMA value for a given level

Parameters
adaptThe adaptation context
levelThe level to query
is_short1 to query the short term EWMA, 0 for the long term EWMA

Returns the currently tracked EWMA value for a specific level.