srt_protocol/options/receiver.rs
1use std::time::Duration;
2
3use super::*;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
6pub struct Receiver {
7 /// SRTO_RCVLATENCY
8 ///
9 /// The latency value in the receiving direction of the socket. This value is only significant when
10 /// SRTO_TSBPDMODE is enabled.
11 ///
12 /// Default value: 120 ms in Live mode, 0 in File mode (see SRTO_TRANSTYPE).
13 ///
14 /// The latency value defines the minimum receiver buffering delay before delivering an SRT data
15 /// packet from a receiving SRT socket to a receiving application. The provided value is used in
16 /// the connection establishment (handshake exchange) stage to fix the end-to-end latency of the
17 /// transmission. The effective end-to-end latency L will be fixed as the network transmission time
18 /// of the final handshake packet (~1/2 RTT) plus the negotiated latency value Ln. Data packets will
19 /// stay in the receiver buffer for at least L microseconds since the timestamp of the packet,
20 /// independent of the actual network transmission times (RTT variations) of these packets.
21 ///
22 /// The actual value of the receiver buffering delay Ln (the negotiated latency) used on a
23 /// connection is determined by the negotiation in the connection establishment (handshake exchange)
24 /// phase as the maximum of the SRTO_RCVLATENCY value and the value of SRTO_PEERLATENCY set by the
25 /// peer.
26 ///
27 /// Reading the SRTO_RCVLATENCY value on a socket after the connection is established provides the
28 /// actual (negotiated) latency value Ln.
29 ///
30 /// The receiver's buffer must be large enough to store the L segment of the stream, i.e. L ×
31 /// Bitrate bytes. Refer to SRTO_RCVBUF.
32 ///
33 /// The sender's buffer must be large enough to store a packet up until it is either delivered (and
34 /// acknowledged) or dropped by the sender due to it becoming too late to be delivered. In other
35 /// words, D × Bitrate bytes, where D is the sender's drop delay value configured with
36 /// SRTO_SNDDROPDELAY.
37 ///
38 /// Buffering of data packets on the receiving side makes it possible to recover from packet losses
39 /// using the ARQ (Automatic Repeat Request) technique, and to deal with varying RTT times (network
40 /// jitter) in the network, providing a (close to) constant end-to-end latency of the transmission.
41 pub latency: Duration,
42
43 /// SRTO_LOSSMAXTTL
44 /// The value up to which the Reorder Tolerance may grow. The Reorder Tolerance is the number of
45 /// packets that must follow the experienced "gap" in sequence numbers of incoming packets so
46 /// that the loss report is sent (in the hope that the gap is due to packet reordering rather
47 /// than because of loss). The value of Reorder Tolerance starts from 0 and is set to a greater
48 /// value when packet reordering is detected This happens when a "belated" packet, with sequence
49 /// number older than the latest received, has been received, but without retransmission flag.
50 /// When this is detected the Reorder Tolerance is set to the value of the interval between
51 /// latest sequence and this packet's sequence, but not more than the value set by
52 /// SRTO_LOSSMAXTTL. By default this value is set to 0, which means that this mechanism is off.
53 pub reorder_tolerance_max: PacketCount,
54
55 /// SRTO_RCVBUF
56 ///
57 /// Receive Buffer Size, in bytes. Note, however, that the internal setting of this value is in
58 /// the number of buffers, each one of size equal to SRT payload size, which is the value of
59 /// SRTO_MSS decreased by UDP and SRT header sizes (28 and 16). The value set here will be
60 /// effectively aligned to the multiple of payload size.
61 ///
62 /// Minimum value: 32 buffers (46592 with default value of SRTO_MSS).
63 ///
64 /// Maximum value: SRTO_FC number of buffers (receiver buffer must not be greater than the
65 /// Flight Flag size).
66 pub buffer_size: ByteCount,
67
68 /// SRTO_NAKREPORT
69 /// When set to true, every report for a detected loss will be repeated when the timeout for the
70 /// expected retransmission of this loss has expired and the missing packet still wasn't
71 /// recovered, or wasn't conditionally dropped (see SRTO_TLPKTDROP).
72 ///
73 /// The default is true for Live mode
74 pub nak_report: bool,
75
76 ///SRTO_TLPKTDROP
77 /// Too-late Packet Drop. When enabled on receiver, it skips missing packets that have not been
78 /// delivered in time and delivers the subsequent packets to the application when their
79 /// time-to-play has come. It also sends a fake ACK to the sender. When enabled on sender and
80 /// enabled on the receiving peer, sender drops the older packets that have no chance to be
81 /// delivered in time. It is automatically enabled in sender if receiver supports it.
82 pub too_late_packet_drop: bool,
83
84 // TODO: What is drift tracer?
85 /// SRTO_DRIFTTRACER - Enable/disable drift tracer - unit: bool, default: true, range: t|f
86 /// Enables or disables time drift tracer (receiver).
87 pub drift_tracer: bool,
88}
89
90impl Default for Receiver {
91 fn default() -> Self {
92 Self {
93 latency: Duration::from_millis(120),
94 reorder_tolerance_max: PacketCount(0),
95 buffer_size: ByteCount(8192 * 1500),
96 nak_report: true,
97 too_late_packet_drop: true,
98 drift_tracer: false,
99 }
100 }
101}
102
103impl Validation for Receiver {
104 type Error = OptionsError;
105
106 fn is_valid(&self) -> Result<(), Self::Error> {
107 use OptionsError::*;
108 if self.buffer_size < ByteCount(46592) {
109 Err(ReceiveBufferMin(self.buffer_size))
110 } else {
111 Ok(())
112 }
113 }
114}
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 use OptionsError::*;
121
122 #[test]
123 fn validation() {
124 let result = Receiver {
125 buffer_size: ByteCount(46591),
126 ..Default::default()
127 };
128
129 assert_eq!(
130 result.try_validate(),
131 Err(ReceiveBufferMin(ByteCount(46591)))
132 );
133 }
134}