Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
stream::adaptive_fec_t Class Reference

#include <src/adaptive_fec.h>

Public Member Functions

int percentage (std::uint64_t sent_total, std::uint64_t missing_total, std::uint64_t reported_total, std::int64_t now_ms, int configured, int ceiling)
bool has_sample (std::int64_t second) const
 True once some second in the window carried enough packets to judge.
double worst_loss (std::int64_t second) const
 The worst packet-loss ratio in the window, 0 when no bucket is trustworthy.

Static Public Member Functions

static bool trusted (const bucket_t &bucket, std::int64_t second)
static int percentage_for (double loss, int ceiling)
static double unrecoverable_chance (int data, int parity, double loss)
 P(more than parity packets of an (n + parity) block are lost).

Static Public Attributes

static constexpr int window_seconds = 10
 Seconds of history the estimate looks at.
static constexpr int min_percentage = 1
 Never ask for less than this, and never more than the configured ceiling.
static constexpr int max_percentage = 50
static constexpr double target_unrecoverable = 0.001
 Target chance that any one FEC block cannot be rebuilt.
static constexpr int representative_data_shards = 10
 Data shards assumed per block when turning a target into a percentage.
static constexpr std::uint64_t min_packets_per_bucket = 100
 A second needs at least this many sent data packets before its ratio is trusted.
static constexpr std::int64_t lower_cooldown_ms = 5000
 How long a lower estimate must hold before it is applied.
static constexpr std::int64_t bucket_span_ms = 1000
 A bucket must cover this much time before its ratio is trusted.
static constexpr std::int64_t min_coverage_ms = bucket_span_ms * 3 / 4

Detailed Description

Chooses how much parity the next frame gets.

The client already tells us what it lost: SS_FRAME_FEC_STATUS (0x5502) reports every block that needed parity or was dropped, and video_loss_monitor_t turns those into cumulative packet counters. This class samples those counters once per second into a ten-second window and keeps the worst second, because picture loss is caused by bursts, not by the average.

The decision asks for the smallest redundancy whose chance of leaving a block unrecoverable is at most 0.1% at the observed loss rate. A raise applies as soon as a lossy second is counted, with no hold; lowering waits five seconds, so a single clean second does not start a redundancy sawtooth.

Header-only and dependency-free so it can be unit tested without a session.

Definition at line 32 of file adaptive_fec.h.

Member Function Documentation

◆ has_sample()

bool stream::adaptive_fec_t::has_sample ( std::int64_t second) const
inline

True once some second in the window carried enough packets to judge.

Definition at line 160 of file adaptive_fec.h.

◆ percentage()

int stream::adaptive_fec_t::percentage ( std::uint64_t sent_total,
std::uint64_t missing_total,
std::uint64_t reported_total,
std::int64_t now_ms,
int configured,
int ceiling )
inline

The percentage to encode the next frame with.

Parameters
sent_totalData packets sent so far (video_loss_monitor_t::sent_data_packets()): the client only looks at a block until it can rebuild it, so loss is measured against data.
missing_totalPackets the client reported missing (video_loss_monitor_t::missing_packets()).
reported_totalBlocks the client reported on (video_loss_monitor_t::reported_blocks()). Zero means the client has never sent SS_FRAME_FEC_STATUS, which is not evidence of a clean link: the configured value stands.
now_msMonotonic milliseconds.
configuredThe operator's configured percentage, used as is until the window has data.
ceilingThe highest percentage the estimate may ask for.

Definition at line 78 of file adaptive_fec.h.

◆ percentage_for()

int stream::adaptive_fec_t::percentage_for ( double loss,
int ceiling )
inlinestatic

The smallest percentage whose unrecoverable-block chance stays under target.

Parameters
lossPacket loss ratio in [0, 1].
ceilingHighest percentage allowed.

Definition at line 204 of file adaptive_fec.h.

◆ trusted()

bool stream::adaptive_fec_t::trusted ( const bucket_t & bucket,
std::int64_t second )
inlinestatic

Whether a bucket may influence the estimate.

It must carry enough packets, span close to a whole second (crossing a clock-second boundary is not the same as sampling one), and still be inside the window: a stall must not let a sample from twenty seconds ago keep parity high.

Definition at line 189 of file adaptive_fec.h.

◆ unrecoverable_chance()

double stream::adaptive_fec_t::unrecoverable_chance ( int data,
int parity,
double loss )
inlinestatic

P(more than parity packets of an (n + parity) block are lost).

Definition at line 221 of file adaptive_fec.h.

◆ worst_loss()

double stream::adaptive_fec_t::worst_loss ( std::int64_t second) const
inline

The worst packet-loss ratio in the window, 0 when no bucket is trustworthy.

Definition at line 170 of file adaptive_fec.h.

Member Data Documentation

◆ bucket_span_ms

std::int64_t stream::adaptive_fec_t::bucket_span_ms = 1000
staticconstexpr

A bucket must cover this much time before its ratio is trusted.

Definition at line 48 of file adaptive_fec.h.

◆ lower_cooldown_ms

std::int64_t stream::adaptive_fec_t::lower_cooldown_ms = 5000
staticconstexpr

How long a lower estimate must hold before it is applied.

Definition at line 46 of file adaptive_fec.h.

◆ max_percentage

int stream::adaptive_fec_t::max_percentage = 50
staticconstexpr

Definition at line 38 of file adaptive_fec.h.

◆ min_coverage_ms

std::int64_t stream::adaptive_fec_t::min_coverage_ms = bucket_span_ms * 3 / 4
staticconstexpr

A bucket cut short by a clock boundary still counts if it is this close to a full second.

Rollovers happen when a frame lands in the next second, so with jitter a bucket can cover 998 ms; demanding a whole second would throw that away and the next bucket would start short as well, pushing the first estimate out by seconds.

Definition at line 54 of file adaptive_fec.h.

◆ min_packets_per_bucket

std::uint64_t stream::adaptive_fec_t::min_packets_per_bucket = 100
staticconstexpr

A second needs at least this many sent data packets before its ratio is trusted.

Definition at line 44 of file adaptive_fec.h.

◆ min_percentage

int stream::adaptive_fec_t::min_percentage = 1
staticconstexpr

Never ask for less than this, and never more than the configured ceiling.

Definition at line 37 of file adaptive_fec.h.

◆ representative_data_shards

int stream::adaptive_fec_t::representative_data_shards = 10
staticconstexpr

Data shards assumed per block when turning a target into a percentage.

Definition at line 42 of file adaptive_fec.h.

◆ target_unrecoverable

double stream::adaptive_fec_t::target_unrecoverable = 0.001
staticconstexpr

Target chance that any one FEC block cannot be rebuilt.

Definition at line 40 of file adaptive_fec.h.

◆ window_seconds

int stream::adaptive_fec_t::window_seconds = 10
staticconstexpr

Seconds of history the estimate looks at.

Definition at line 35 of file adaptive_fec.h.


The documentation for this class was generated from the following file: