|
Hermes 0.7.0
Linux game streaming host
|
#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 |
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.
|
inline |
True once some second in the window carried enough packets to judge.
Definition at line 160 of file adaptive_fec.h.
|
inline |
The percentage to encode the next frame with.
| sent_total | Data 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_total | Packets the client reported missing (video_loss_monitor_t::missing_packets()). |
| reported_total | Blocks 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_ms | Monotonic milliseconds. |
| configured | The operator's configured percentage, used as is until the window has data. |
| ceiling | The highest percentage the estimate may ask for. |
Definition at line 78 of file adaptive_fec.h.
|
inlinestatic |
The smallest percentage whose unrecoverable-block chance stays under target.
| loss | Packet loss ratio in [0, 1]. |
| ceiling | Highest percentage allowed. |
Definition at line 204 of file adaptive_fec.h.
|
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.
|
inlinestatic |
P(more than parity packets of an (n + parity) block are lost).
Definition at line 221 of file adaptive_fec.h.
|
inline |
The worst packet-loss ratio in the window, 0 when no bucket is trustworthy.
Definition at line 170 of file adaptive_fec.h.
|
staticconstexpr |
A bucket must cover this much time before its ratio is trusted.
Definition at line 48 of file adaptive_fec.h.
|
staticconstexpr |
How long a lower estimate must hold before it is applied.
Definition at line 46 of file adaptive_fec.h.
|
staticconstexpr |
Definition at line 38 of file adaptive_fec.h.
|
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.
|
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.
|
staticconstexpr |
Never ask for less than this, and never more than the configured ceiling.
Definition at line 37 of file adaptive_fec.h.
|
staticconstexpr |
Data shards assumed per block when turning a target into a percentage.
Definition at line 42 of file adaptive_fec.h.
|
staticconstexpr |
Target chance that any one FEC block cannot be rebuilt.
Definition at line 40 of file adaptive_fec.h.
|
staticconstexpr |
Seconds of history the estimate looks at.
Definition at line 35 of file adaptive_fec.h.