Debian Codegraph @

src/rist-bandwidth-guard.h

raw symbols SCIP
1 /* librist. SPDX-License-Identifier: BSD-2-Clause
2 *
3 * Whether a sender peer has any retransmission budget left to work with, and
4 * whether it is time to say so again. Kept in a small standalone header so
5 * both can be unit-tested without a peer or a running sender.
6 */
7
8 #ifndef RIST_BANDWIDTH_GUARD_H
9 #define RIST_BANDWIDTH_GUARD_H
10
11 #include <stdbool.h>
12 #include <stddef.h>
13 #include <stdint.h>
14
15 /* Is the retransmission budget structurally exhausted?
16 *
17 * The bandwidth ceiling (?bandwidth=, recovery_maxbitrate) is not a limit on
18 * payload: rist_retry_dequeue() refuses a retransmission whenever payload plus
19 * retransmit bitrate would cross it, so what the ceiling really bounds is the
20 * two together. Set it at or below the payload rate and the budget is nil --
21 * every NACK is refused for as long as the stream runs, and the only trace is a
22 * debug-level line nobody has enabled. What the operator sees is a link that
23 * never recovers a lost packet, which reads as a bad network rather than a bad
24 * ceiling, so it is worth saying out loud.
25 *
26 * payload and ceiling share one unit (bits per second). A ceiling of 0 means
27 * "unset" everywhere it can still be seen -- init_peer_settings() replaces it
28 * with the default before a peer runs -- so there is nothing to have exceeded. */
29 static inline bool
30 rist_retransmit_budget_starved(size_t payload_bps, size_t ceiling_bps)
31 {
32 if (!ceiling_bps)
33 return false;
34 return payload_bps >= ceiling_bps;
35 }
36
37 /* Rate-limit for the warning above, which is evaluated once per stats interval
38 * and would otherwise repeat every second for the life of a misconfigured
39 * stream. Still repeats, because a single line at startup scrolls away long
40 * before anyone goes looking for why nothing recovers.
41 *
42 * last is when it was last emitted (0 if never) and shares one unit with now.
43 * A now behind last emits, which is the harmless reading of a clock that moved
44 * backwards. */
45 static inline bool
46 rist_bandwidth_warn_due(uint64_t last, uint64_t interval, uint64_t now)
47 {
48 if (!last || now < last)
49 return true;
50 return (now - last) >= interval;
51 }
52
53 #endif /* RIST_BANDWIDTH_GUARD_H */