srt_protocol/options/bandwidth.rs
1// rate in bytes per second
2use super::*;
3
4/// https://datatracker.ietf.org/doc/html/draft-sharabayko-srt-00#section-5.1.1
5///
6/// Note that Maximum Bandwidth, Input Rate, and Input Rate Estimate are bytes per second
7/// and Overhead is a percentage.
8#[derive(Debug, Clone, Eq, PartialEq, Default)]
9pub enum LiveBandwidthMode {
10 /// Set the maximum bandwidth explicitly.
11 ///
12 /// The recommended default value is 1 Gbps. The default value is set only for live streaming.
13 ///
14 /// Note that this static setting is not well-suited to a variable input, like when you change
15 /// the bitrate on an encoder. Each time the input bitrate is configured on the encoder, this
16 /// value should also be reconfigured.
17 Max(DataRate), // m_llMaxBW != 0
18
19 /// Set the SRT send input rate and overhead.
20 /// In this mode, SRT calculates the maximum bandwidth as follows:
21 ///
22 /// Maximum Bandwidth = Input Rate * (1 + Overhead / 100)
23 ///
24 /// Note that Input mode reduces to the Set mode and the same restrictions apply.
25 Input {
26 // m_llInputBW != 0
27 rate: DataRate, // m_llInputBW
28 overhead: Percent, // m_iOverheadBW
29 },
30
31 /// Measure the SRT send input rate internally and set the Overhead.
32 ///
33 /// In this mode, SRT adjusts the value of maximum bandwidth each time it gets the updated
34 /// Input Rate Estimate of the Input Rate:
35 ///
36 /// Maximum Bandwidth = Input Rate Estimate * (1 + Overhead / 100)
37 ///
38 /// Estimated mode is recommended for setting the Maximum Bandwidth as it follows the
39 /// fluctuations in SRT send Input Rate. However, there are certain considerations that
40 /// should be taken into account.
41 ///
42 ///
43 /// In Estimated mode, SRT takes as an initial Expected Input Rate. This should match the
44 /// configured output bitrate rate of an encoder (in terms of bitrate for the packets including
45 /// audio and overhead). But it is normal for an encoder to occasionally overshoot. At a low
46 /// bitrate, sometimes an encoder can be too optimistic and will output more bits than expected.
47 /// Under these conditions, SRT packets would not go out fast enough because the configured
48 /// bandwidth limitation would be too low. This is mitigated by calculating the bitrate
49 /// internally.
50 ///
51 /// SRT examines the packets being submitted and calculates an Input Rate Estimate as a moving
52 /// average. However, this introduces a bit of a delay based on the content. It also means that
53 /// if an encoder encounters black screens or still frames, this would dramatically lower the
54 /// bitrate being measured, which would in turn reduce the SRT output rate. And then, when the
55 /// video picks up again, the input rate rises sharply. SRT would not start up again fast
56 /// enough on output because of the time it takes to measure the speed. Packets might be
57 /// accumulated in the SRT send buffer, and delayed as a result, causing them to arrive too late
58 /// at the decoder, and possible drops by the receiver.
59 Estimated {
60 // m_llMaxBW == 0 && m_llInputBW == 0
61 overhead: Percent, // m_iOverheadBW
62 expected: DataRate, // SRTO_MININPUTBW
63 },
64 #[default]
65 Unlimited,
66}