srt_protocol/statistics/mod.rs
1pub use super::listener::ListenerStatistics;
2
3use std::time::Duration;
4
5/// SRT provides a powerful set of statistical data on a socket. This data can be used to keep an eye
6/// on a socket's health and track faulty behavior.
7///
8/// Statistics are calculated independently on each side (receiver and sender) and are not exchanged
9/// between peers unless explicitly stated.
10#[derive(Debug, Eq, PartialEq, Default, Clone)]
11#[non_exhaustive]
12pub struct SocketStatistics {
13 /// The time elapsed, in milliseconds, since the SRT socket was created.
14 pub elapsed_time: Duration, // msTimeStamp
15
16 pub tx_all_packets: u64,
17 pub rx_all_packets: u64,
18
19 pub tx_all_bytes: u64,
20 pub rx_all_bytes: u64,
21
22 pub tx_encrypted_data: u64,
23 pub rx_decrypted_data: u64,
24
25 pub rx_clock_adjustments: u64,
26 pub rx_clock_drift_mean: i64,
27 pub rx_clock_drift_stddev: i64,
28
29 pub rx_ack2_errors: i64,
30
31 /// The total number of sent DATA packets, including retransmissions ([tx_retransmit_data](#tx_retransmit_data)).
32 //
33 // TODO: Should we do this too?
34 // If the SRTO_PACKETFILTER socket option is enabled (refer to SRT API Socket Options), this statistic counts sent packet filter control packets (pktSndFilterExtraTotal) as well. Introduced in SRT v1.4.0.
35 pub tx_data: u64, // pktSentTotal
36
37 /// The total number of received DATA packets, including retransmissions ([rx_retransmit_data](#tx_retransmit_data)).
38 //
39 // TODO: Should we do this too?
40 // If the `SRTO_PACKETFILTER` socket option is enabled (refer to [SRT API Socket Options](API-socket-options.md)), this statistic counts received packet filter control packets ([pktRcvFilterExtraTotal](#pktRcvFilterExtraTotal)) as well. Introduced in SRT v1.4.0.
41 pub rx_data: u64, // pktRecvTotal
42
43 /// The total number of sent *unique* DATA packets.
44 ///
45 /// This value contains only *unique* *original* DATA packets. Retransmitted DATA packets
46 /// ([tx_retransmit_data](#tx_retransmit_data)) are not taken into account.
47 ///
48 /// This value corresponds to the number of original DATA packets sent by the SRT sender. It
49 /// counts every packet sent over the network for the first time, and can be calculated as
50 /// follows: `tx_unique_data = tx_data – tx_retransmit_data`. The original DATA packets are sent
51 /// only once.
52 //
53 // TODO: Should we do this?
54 // or by `pktSentUniqueTotal = pktSentTotal – pktRetransTotal - pktSndFilterExtraTotal` if the `SRTO_PACKETFILTER` socket option is enabled
55 // If the `SRTO_PACKETFILTER` socket option is enabled (refer to [SRT API Socket Options](API-socket-options.md)), packet filter control packets ([pktSndFilterExtraTotal](#pktSndFilterExtraTotal)) are also not taken into account.
56 pub tx_unique_data: u64, // pktSentUniqueTotal
57
58 /// The total number of received *unique* original, retransmitted or recovered DATA packets
59 /// *received in time*, *decrypted without errors* and, as a result, scheduled for delivery to
60 /// the upstream application by the SRT receiver.
61 ///
62 /// Unique means "first arrived" DATA packets. There is no difference whether a packet is
63 /// original or, in case of loss, retransmitted or recovered by the packet filter. Whichever
64 /// packet comes first is taken into account.
65 ///
66 /// This statistic doesn't count
67 ///
68 /// - duplicate packets (retransmitted or sent several times by defective hardware/software),
69 /// - arrived too late packets (retransmitted or original packets arrived out of order) that
70 /// were already dropped by the TLPKTDROP mechanism (see [tx_dropped_data](#tx_dropped_data)
71 /// statistic),
72 /// - arrived in time packets, but decrypted with errors (see [rx_decrypt_errors](#rx_decrypt_errors)
73 /// statistic), and, as a result, dropped by the TLPKTDROP mechanism (see [tx_dropped_data](#tx_dropped_data)
74 /// statistic).
75 //
76 // TODO: Should we do this?
77 // DATA packets recovered by the packet filter ([pktRcvFilterSupplyTotal](#pktRcvFilterSupplyTotal)) are taken into account if the `SRTO_PACKETFILTER` socket option is enabled (refer to [SRT API Socket Options](API-socket-options.md)). Do not mix up with the control packets received by the packet filter ([pktRcvFilterExtraTotal](#pktRcvFilterExtraTotal)).
78 pub rx_unique_data: u64, // pktRecvUniqueTotal
79
80 /// The total number of data packets considered or reported as lost at the sender side. Does not
81 /// correspond to the packets detected as lost at the receiver side.
82 ///
83 /// A packet is considered lost in two cases:
84 /// 1. Sender receives a loss report (NAK) from a receiver.
85 /// 2. Sender initiates retransmission after not receiving an ACK packet for a certain timeout.
86 /// Refer to `FASTREXMIT` and `LATEREXMIT` algorithms.
87 pub tx_loss_data: u64, // pktSndLossTotal
88
89 /// The total number of SRT DATA packets detected as presently missing (either reordered or lost)
90 /// at the receiver side.
91 ///
92 /// The detection of presently missing packets is triggered by a newly received DATA packet with
93 /// the sequence number `s`. If `s` is greater than the sequence number `next_exp` of the next
94 /// expected packet (`s > next_exp`), the newly arrived packet `s` is considered in-order and
95 /// there is a sequence discontinuity of size `s - next_exp` associated with this packet. The
96 /// presence of sequence discontinuity means that some packets of the original sequence have
97 /// not yet arrived (presently missing), either reordered or lost. Once the sequence discontinuity
98 /// is detected, its size `s - next_exp` is added to `rx_loss_data` statistic. Refer to
99 /// [RFC 4737 - Packet Reordering Metrics](https://tools.ietf.org/html/rfc4737) for details.
100 ///
101 /// If the packet `s` is received out of order (`s < next_exp`), the statistic is not affected.
102 ///
103 /// Note that only original (not retransmitted) SRT DATA packets are taken into account. Refer to
104 /// [rx_retransmit_data](#rx_retransmit_data) for the formula for obtaining the total number of
105 /// lost retransmitted packets.
106 //
107 // TODO: ensure this is implemented correctly
108 // In SRT v1.4.0, v1.4.1, the `pktRcvLossTotal` statistic includes packets that failed to be decrypted. To receive the number of presently missing packets, substract [pktRcvUndecryptTotal](#pktRcvUndecryptTotal) from the current one. This is going to be fixed in SRT v.1.5.0.
109 pub rx_loss_data: u64, // pktRcvLossTotal
110
111 /// The total number of retransmitted packets sent by the SRT sender.
112 ///
113 /// This statistic is not interchangeable with the receiver [rx_retransmit_data](#rx_retransmit_data)
114 /// statistic.
115 pub tx_retransmit_data: u64, // pktRetransTotal
116
117 /// The total number of retransmitted packets registered at the receiver side.
118 ///
119 /// This statistic is not interchangeable with the sender [tx_retransmit_data](#tx_retransmit_data)
120 /// statistic.
121 ///
122 /// Note that the total number of lost retransmitted packets can be calculated as the total
123 /// number of retransmitted packets sent by receiver minus the total number of retransmitted
124 /// packets registered at the receiver side: `tx_retransmit_data - rx_retransmit_data`.
125 //
126 // TODO: ensure this is implemented correctly
127 // This is going to be implemented in SRT v1.5.0, see issue [#1208](https://github.com/Haivision/srt/issues/1208).
128 pub rx_retransmit_data: u64, // pktRcvRetransTotal
129
130 /// The total number of sent ACK (Acknowledgement) control packets.
131 pub tx_ack: u64, // pktSentACKTotal
132
133 /// The total number of received ACK (Acknowledgement) control packets.
134 pub rx_ack: u64, // pktRecvACKTotal
135
136 pub tx_light_ack: u64,
137
138 pub rx_light_ack: u64,
139
140 /// The total number of sent NAK (Negative Acknowledgement) control packets.
141 pub tx_nak: u64, // pktSentNAKTotal
142
143 /// The total number of received NAK (Negative Acknowledgement) control packets.
144 pub rx_nak: u64, // pktRecvNAKTotal
145
146 /// The total number of sent ACK2 (Acknowledgement Acknowledgement) control packets.
147 pub tx_ack2: u64,
148
149 /// The total number of received ACK2 (Acknowledgement Acknowledgement) control packets.
150 pub rx_ack2: u64,
151
152 /// The total accumulated time, during which the SRT sender has some data to
153 /// transmit, including packets that have been sent, but not yet acknowledged. In other words,
154 /// the total accumulated duration in microseconds when there was something to deliver (non-empty
155 /// senders' buffer).
156 pub tx_buffer_time: Duration, // usSndDurationTotal
157
158 /// The total number of DATA packets _dropped_ by the SRT sender that have no chance to be
159 /// delivered in time (refer to [TLPKTDROP](https://github.com/Haivision/srt-rfc/blob/master/draft-sharabayko-mops-srt.md#too-late-packet-drop-too-late-packet-drop)
160 /// mechanism).
161 ///
162 /// Packets may be dropped conditionally when both `SRTO_TSBPDMODE` and `SRTO_TLPKTDROP` socket
163 /// options are enabled, refer to [SRT API Socket Options](API-socket-options.md).
164 ///
165 /// The delay before TLPKTDROP mechanism is triggered is calculated as follows
166 /// `SRTO_PEERLATENCY + SRTO_SNDDROPDELAY + 2 * interval between sending ACKs`,
167 /// where `SRTO_PEERLATENCY` is the configured SRT latency, `SRTO_SNDDROPDELAY` adds an extra to
168 /// `SRTO_PEERLATENCY` delay, the default `interval between sending ACKs` is 10 milliseconds. The
169 /// minimum delay is `1000 + 2 * interval between sending ACKs` milliseconds.
170 //
171 // TODO: Should we provide these configuration options?
172 // Refer to `SRTO_PEERLATENCY`, `SRTO_SNDDROPDELAY` socket options in [SRT API Socket Options](API-socket-options.md).
173 pub tx_dropped_data: u64, // pktSndDropTotal
174
175 /// The total number of DATA packets _dropped_ by the SRT receiver and, as a result, not delivered to the upstream application (refer to [TLPKTDROP](https://github.com/Haivision/srt-rfc/blob/master/draft-sharabayko-mops-srt.md#too-late-packet-drop-too-late-packet-drop) mechanism).
176 ///
177 /// This statistic counts
178 /// - arrived too late packets (retransmitted or original packets arrived out of order),
179 /// - arrived in time packets, but decrypted with errors (see also [rx_decrypt_errors](#rx_decrypt_errors) statistic).
180 //
181 // TODO: Should we provide these configuration options?
182 // Packets may be dropped conditionally when both `SRTO_TSBPDMODE` and `SRTO_TLPKTDROP` socket options are enabled, refer to [SRT API Socket Options](API-socket-options.md).
183 pub rx_dropped_data: u64, // pktRcvDropTotal
184
185 /// The total number of packets that failed to be decrypted at the receiver side.
186 pub rx_decrypt_errors: u64, // pktRcvUndecryptTotal
187
188 // The total number of packet filter control packets generated by the packet filter (refer to [SRT Packet Filtering & FEC](../features/packet-filtering-and-fec.md)).
189 //
190 // Packet filter control packets contain only control information necessary for the packet filter. The type of these packets is DATA.
191 //
192 // If the `SRTO_PACKETFILTER` socket option is disabled (refer to [SRT API Socket Options](API-socket-options.md)), this statistic is equal to 0. Introduced in SRT v1.4.0.
193 //
194 // TODO: this probably won't be implemented; extensible packet filtering seems like over engineering
195 // #### pktSndFilterExtraTotal
196
197 // The total number of packet filter control packets received by the packet filter (refer to [SRT Packet Filtering & FEC](../features/packet-filtering-and-fec.md)).
198 //
199 // Packet filter control packets contain only control information necessary for the packet filter. The type of these packets is DATA.
200 //
201 // If the `SRTO_PACKETFILTER` socket option is disabled (refer to [SRT API Socket Options](API-socket-options.md)), this statistic is equal to 0. Introduced in SRT v1.4.0.
202 //
203 // TODO: this probably won't be implemented; extensible packet filtering seems like over engineering
204 // #### pktRcvFilterExtraTotal
205
206 // The total number of lost DATA packets recovered by the packet filter at the receiver side (e.g., FEC rebuilt packets; refer to [SRT Packet Filtering & FEC](../features/packet-filtering-and-fec.md)).
207 //
208 // If the `SRTO_PACKETFILTER` socket option is disabled (refer to [SRT API Socket Options](API-socket-options.md)), this statistic is equal to 0. Introduced in SRT v1.4.0.
209 //
210 // TODO: this probably won't be implemented; extensible packet filtering seems like over engineering
211 // #### pktRcvFilterSupplyTotal
212
213 // The total number of lost DATA packets **not** recovered by the packet filter at the receiver side (refer to [SRT Packet Filtering & FEC](../features/packet-filtering-and-fec.md)).
214 //
215 // If the `SRTO_PACKETFILTER` socket option is disabled (refer to [SRT API Socket Options](API-socket-options.md)), this statistic is equal to 0. Introduced in SRT v1.4.0.
216 //
217 // TODO: this probably won't be implemented; extensible packet filtering seems like over engineering
218 // #### pktRcvFilterLossTotal
219 /// Same as [tx_data](#tx_data), but expressed in bytes, including payload and all the headers
220 /// (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
221 pub tx_bytes: u64, // byteSentTotal
222
223 /// Same as [rx_data](#rx_data), but expressed in bytes, including payload and all the headers
224 /// (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
225 pub rx_bytes: u64, // byteRecvTotal
226
227 /// Same as [tx_unique_data](#tx_unique_data), but expressed in bytes, including payload and all
228 /// the headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
229 pub tx_unique_bytes: u64, // byteSentUniqueTotal
230
231 /// Same as [rx_unique_data](#tx_unique_data), but expressed in bytes, including payload and all
232 /// the headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
233 pub rx_unique_bytes: u64, // byteRecvUniqueTotal
234
235 /// Same as [rx_loss_data](#rx_loss_data), but expressed in bytes, including payload and all the
236 /// headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT). Bytes for the presently missing (either
237 /// reordered or lost) packets' payloads are estimated based on the average packet size.
238 pub rx_loss_bytes: u64, // byteRcvLossTotal
239
240 /// Same as [tx_retransmit_data](#tx_retransmit_data), but expressed in bytes, including payload
241 /// and all the headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
242 pub tx_retransmit_bytes: u64, // byteRetransTotal
243
244 /// Same as [tx_dropped_data](#tx_dropped_data), but expressed in bytes, including payload and
245 /// all the headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
246 pub tx_dropped_bytes: u64, // byteSndDropTotal
247
248 /// Same as [rx_dropped_data](#rx_dropped_data), but expressed in bytes, including payload and
249 /// all the headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT). Bytes for the dropped packets'
250 /// payloads are estimated based on the average packet size.
251 // TODO: do we really need this?
252 // this could be calculated based on rx_dropped_data * (tx_data_bytes / tx_data)
253 pub rx_dropped_bytes: u64, // byteRcvDropTotal
254
255 /// Same as [rx_decrypt_errors](#rx_decrypt_errors), but expressed in bytes, including payload
256 /// and all the headers (20 bytes IPv4 + 8 bytes UDP + 16 bytes SRT).
257 pub rx_decrypt_error_bytes: u64, // byteRcvUndecryptTotal
258
259 /// Current minimum time interval between which consecutive packets are sent microseconds.
260 ///
261 /// The `tx_snd_period` is the minimum time (sending period) that must be kept between two
262 /// packets sent consecutively over the link used by an SRT socket. It is not the EXACT time
263 /// interval between two consecutive packets. In the case where the time spent by an application
264 /// between sending two consecutive packets exceeds `tx_snd_period`, the next packet will be
265 /// sent faster, or even immediately, to preserve the average sending rate.
266 ///
267 /// **Note**: Does not apply to probing packets.
268 // TODO: This isn't true, should it be?
269 // Note that several sockets sharing one outgoing port use the same sending queue.
270 // They may have different pacing of the outgoing packets, but all the packets will
271 // be placed in the same sending queue, which may affect the send timing.
272 pub tx_snd_period: Duration, // usPktSndPeriod
273
274 /// The maximum number of packets that can be "in flight".
275 /// See also [tx_unacknowledged_data](#tx_unacknowledged_data).
276 ///
277 /// The value retrieved on the sender side represents an estimation of the amount of free space
278 /// in the buffer of the peer receiver. The actual amount of available space is periodically
279 /// reported back by the receiver in ACK packets. When this value drops to zero, the next packet
280 /// sent will be dropped by the receiver without processing. The receiver buffer contents should
281 /// normally occupy no more than half of the buffer size (default 8192). If `tx_flow_window`
282 /// value is less than that and becomes even less in the next reports, it means that the receiver
283 /// application on the peer side cannot process the incoming stream fast enough and this may lead
284 /// to a dropped connection.
285 //
286 // TODO: Should we implement this?
287 // In **file mode** this may cause a slowdown of sending in
288 // order to wait until the receiver has more space available, after it
289 // eventually extracts the packets waiting in its receiver buffer; in **live
290 // mode**
291 pub tx_flow_window: u64, // pktFlowWindow
292
293 // Congestion window size, in number of packets.
294 //
295 // Dynamically limits the maximum number of packets that can be in flight.
296 // Congestion control module dynamically changes the value.
297 //
298 // In **file mode** this value starts at 16 and is increased to the number of reported
299 // acknowledged packets. This value is also updated based on the delivery rate, reported by the
300 // receiver. It represents the maximum number of packets that can be safely sent without causing
301 // network congestion. The higher this value is, the faster the packets can be sent.
302 // In **live mode** this field is not used.
303 // TODO: Should we implement this?
304 // it's only for file mode
305 // #### pktCongestionWindow
306 /// The number of packets in flight, therefore `tx_unacknowledged_data <= tx_flow_window`.
307 // TODO: Should we implement this?
308 // it's only for file mode
309 // and `tx_unacknowledged_data <= pktCongestionWindow`
310 ///
311 /// This is the distance between the packet sequence number that was last reported by an ACK
312 /// message and the sequence number of the latest packet sent (at the moment when the statistics
313 /// are being read).
314 ///
315 /// **NOTE:** ACKs are received periodically (at least every 10 ms). This value is most accurate
316 /// just after receiving an ACK and becomes a little exaggerated over time until the next ACK
317 /// arrives. This is because with a new packet sent, while the ACK number stays the same for a
318 /// moment, the value of `tx_unacknowledged_data` increases. But the exact number of packets
319 /// arrived since the last ACK report is unknown. A new statistic might be added which only
320 /// reports the distance between the ACK sequence and the sent sequence at the moment when an
321 /// ACK arrives, and isn't updated until the next ACK arrives. The difference between this value
322 /// and `tx_unacknowledged_data` would then reveal the number of packets with an unknown state
323 /// at that moment.
324 pub tx_unacknowledged_data: u64, // pktFlightSize
325
326 /// Smoothed round-trip time (SRTT), an exponentially-weighted moving average (EWMA) of an
327 /// endpoint's RTT samples, in milliseconds.
328 ///
329 /// See [Section 4.10. Round-Trip Time Estimation](https://tools.ietf.org/html/draft-sharabayko-srt-00#section-4.10)
330 /// of the [SRT RFC](https://datatracker.ietf.org/doc/html/draft-sharabayko-srt-00)
331 /// and [[RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, "Computing TCP's Retransmission Timer"](https://datatracker.ietf.org/doc/html/rfc6298)
332 /// for more details.
333 pub tx_average_rtt: Duration, // msRTT
334 pub rx_average_rtt: Duration,
335
336 /// Estimated bandwidth of the network link.
337 ///
338 /// The bandwidth is estimated at the receiver. The estimation is based on the time between two
339 /// probing DATA packets. Every 16th data packet is sent immediately after the previous data
340 /// packet. By measuring the delay between probe packets on arrival, it is possible to estimate
341 /// the maximum available transmission rate, which is interpreted as the bandwidth of the link.
342 /// The receiver then sends back a running average calculation to the sender with an ACK message.
343 pub tx_bandwidth: u64, // mbpsBandwidth
344 pub rx_bandwidth: u64,
345
346 /// The available space in the sender's buffer.
347 ///
348 /// This value decreases with data scheduled for sending by the application, and increases with
349 /// every ACK received from the receiver, after the packets are sent over the UDP link.
350 pub tx_buffer_available_bytes: u64, // byteAvailSndBuf
351
352 /// The available space in the receiver's buffer, in bytes.
353 ///
354 /// This value increases after the application extracts the data from the socket and decreases
355 /// with every packet received from the sender over the UDP link.
356 pub rx_buffer_available_bytes: u64, // byteAvailRcvBuf
357
358 // Transmission bandwidth limit, in Mbps.
359 // Usually this is the setting from
360 // the `SRTO_MAXBW` option, which may include the value 0 (unlimited). Under certain
361 // conditions a nonzero value might be be provided by a congestion
362 // control module, although none of the built-in congestion control modules
363 // currently use it.
364 //
365 // Refer to `SRTO_MAXBW` and `SRTO_INPUTBW` in [SRT API Socket Options](API-socket-options.md).
366 // TODO: Should we implement this?
367 // it's not actually dynamic, is it? if not then it's uninteresting as a statistic.
368 // #### mbpsMaxBW
369
370 // Maximum Segment Size (MSS), in bytes.
371 // Same as the value from the `SRTO_MSS` socket option.
372 // Should not exceed the size of the maximum transmission unit (MTU), in bytes. Sender and Receiver.
373 // The default size of the UDP packet used for transport,
374 // including all possible headers (Ethernet, IP and UDP), is 1500 bytes.
375 //
376 // Refer to `SRTO_MSS` in [SRT API Socket Options](API-socket-options.md).
377 // TODO: Should we implement this?
378 // it's not actually dynamic, is it? if not then it's uninteresting as a statistic.
379 // #### byteMSS
380
381 // The number of packets in the sender's buffer that are already scheduled for sending or even
382 // possibly sent, but not yet acknowledged.
383 //
384 // Once the receiver acknowledges the receipt of a packet, or the too late packet drop is
385 // triggered, the packet is removed from the sender's buffer. Until this happens, the packet is
386 // considered as unacknowledged.
387 // TODO: also calculate average
388 pub tx_buffered_data: u64, // pktSndBuf
389
390 // Instantaneous (current) value of `tx_buffered_data`, but expressed in bytes, including payload and
391 // all headers (SRT+UDP+IP). \
392 // 20 bytes IPv4 + 8 bytes of UDP + 16 bytes SRT header.
393 // TODO: also calculate average
394 pub tx_buffered_bytes: u64, // byteSndBuf
395
396 // The timespan of packets in the sender's buffer.
397 // TODO: also calculate average
398 pub tx_buffered_time: Duration, // msSndBuf
399
400 // Timestamp-based Packet Delivery Delay value of the peer.
401 // If `SRTO_TSBPDMODE` is on (default for **live mode**), it
402 // returns the value of `SRTO_PEERLATENCY`, otherwise 0.
403 // The sender reports the TSBPD delay value of the receiver.
404 // The receiver reports the TSBPD delay of the sender.
405 // TODO: Should we implement this?
406 // it's not actually dynamic, is it? if not then it's uninteresting as a statistic.
407 // #### msSndTsbPdDelay
408 /// The number of acknowledged packets in receiver's buffer.
409 ///
410 /// This measurement does not include received but not acknowledged packets, stored in the
411 /// receiver's buffer.
412 // TODO: also calculate average
413 pub rx_acknowledged_data: u64, // pktRcvBuf
414
415 /// Instantaneous (current) value of `pktRcvBuf`, expressed in bytes, including payload and all
416 /// headers (SRT+UDP+IP). \
417 /// 20 bytes IPv4 + 8 bytes of UDP + 16 bytes SRT header.
418 // TODO: also calculate average
419 pub rx_acknowledged_bytes: u64, // byteRcvBuf
420
421 /// The timespan of acknowledged packets in the receiver's buffer.
422 ///
423 /// A packet can be acknowledged, but not yet ready to play. This range includes all packets
424 /// regardless of whether they are ready to play or not.
425 /// TODO: also calculate average
426 pub rx_acknowledged_time: Duration, // msRcvBuf
427
428 // Timestamp-based Packet Delivery Delay value set on the socket via `SRTO_RCVLATENCY` or `SRTO_LATENCY`.
429 // The value is used to apply TSBPD delay for reading the received data on the socket.
430 //
431 // If `SRTO_TSBPDMODE` is off (default for **file mode**), 0 is returned.
432 // TODO: Should we implement this?
433 // it's not actually dynamic, is it? if not then it's uninteresting as a statistic.
434 // #### msRcvTsbPdDelay
435
436 // #### pktReorderDistance
437 //
438 // The distance in sequence numbers between the two original (not retransmitted) packets,
439 // that were received out of order.
440 // TODO: Should we implement this?
441 // should we even support maximum reorder tolerance?
442 // The traceable distance values are limited by the maximum reorder tolerance set by `SRTO_LOSSMAXTTL`.
443
444 // Instant value of the packet reorder tolerance. Receiver side. Refer to [pktReorderDistance](#pktReorderDistance).
445 //
446 // `SRTO_LOSSMAXTTL` sets the maximum reorder tolerance value. The value defines the maximum
447 // time-to-live for the original packet, that was received after with a gap in the sequence of incoming packets.
448 // Those missing packets are expected to come out of order, therefore no loss is reported.
449 // The actual TTL value (**pktReorderTolerance**) specifies the number of packets to receive further, before considering
450 // the preceding packets lost, and sending the loss report.
451 //
452 // The internal algorithm checks the order of incoming packets and adjusts the tolerance based on the reorder
453 // distance (**pktReorderTolerance**), but not to a value higher than the maximum (`SRTO_LOSSMAXTTL`).
454 //
455 // SRT starts from tolerance value set in `SRTO_LOSSMAXTTL` (initial tolerance is set to 0 in SRT v1.4.0 and prior versions).
456 // Once the receiver receives the first reordered packet, it increases the tolerance to the distance in the sequence
457 // discontinuity of the two packets. \
458 // After 10 consecutive original (not retransmitted) packets come in order, the reorder distance
459 // is decreased by 1 for every such packet.
460 //
461 // For example, assume packets with the following sequence
462 // numbers are being received: \
463 // 1, 2, 4, 3, 5, 7, 6, 10, 8, 9
464 // SRT starts from 0 tolerance. Receiving packet with sequence number 4 has a discontinuity
465 // equal to one packet. The loss is reported to the sender.
466 // With the next packet (sequence number 3) a reordering is detected. Reorder tolerance is increased to 1. \
467 // The next sequence discontinuity is detected when the packet with sequence number 7 is received.
468 // The current tolerance value is 1, which is equal to the gap (between 5 and 7). No loss is reported. \
469 // Next packet with sequence number 10 has a higher sequence discontinuity equal to 2.
470 // Missing packets with sequence numbers 8 and 9 will be reported lost with the next received packet
471 // (reorder distance is still at 1).
472 // The next received packet has sequence number 8. Reorder tolerance value is increased to 2.
473 // The packet with sequence number 9 is reported lost.
474 // TODO: Should we implement this?
475 // I don't think we've implemented SRTO_LOSSMAXTTL yet, revisit this when/if we do
476 // #### pktReorderTolerance
477 /// The number of packets received but IGNORED due to having arrived too late.
478 ///
479 /// Makes sense only if TSBPD and TLPKTDROP are enabled.
480 ///
481 /// An offset between sequence numbers of the newly arrived DATA packet and latest acknowledged
482 /// DATA packet is calculated. If the offset is negative, the packet is considered late, meaning
483 /// that it was either already acknowledged or dropped by TSBPD as too late to be delivered.
484 ///
485 /// Retransmitted packets can also be considered late.
486 pub rx_belated_data: u64, // pktRcvBelated
487
488 /// Accumulated difference between the current time and the time-to-play of a packet that is
489 /// received late.
490 pub rx_belated_time: Duration, // pktRcvAvgBelatedTime
491}
492
493impl SocketStatistics {
494 pub fn new() -> Self {
495 Self::default()
496 }
497}