1
+
# Configuration Guidelines
2
+
3
+
## Receiver Buffer Size
4
+
5
+
The receiver buffer can be configured with the [`SRTO_RCVBUF`](./API-socket-options.md#SRTO_RCVBUF) socket option.
6
+
Buffer size in bytes is expected to be passed in the `optval` argument of the `srt_setsockopt(..)` function.
7
+
However, internally the value will be converted into the number of packets stored in the receiver buffer.
8
+
9
+
The allowed value of `SRTO_RCVBUF` is also limited by the value of the flow control window size [`SRTO_FC`]((./API-socket-options.md#SRTO_FC) socket option.
10
+
See issue [#700](https://github.com/Haivision/srt/issues/700).
11
+
12
+
The default flow control window size is 25600 packets. It is approximately:
13
+
14
+
- **270 Mbits** of payload in the default live streaming configuration with an SRT payload size of **1316 bytes**;
15
+
- **300 Mbits** of payload in the default file transfer configuration with an SRT payload size of **1456 bytes**.
16
+
17
+
The default receiver buffer size is 8192 packets. It is approximately:
18
+
- **86 Mbits** of payload with the effective SRT payload size of **1316 bytes**.
19
+
20
+
### Setting Receiver Buffer Size
21
+
22
+
As already mentioned, the maximum allowed size of the receiver buffer is limited by the value of `SRTO_FC`.
23
+
When the `SRTO_RCVBUF` option value is set using the `srt_setsockopt(..)` function,
24
+
the provided size in bytes is internally converted to the corresponding size in packets
25
+
using the configured value of the `SRTO_MSS` option to estimate the maximum possible payload of a packet.
26
+
27
+
The following function returns the buffer size in packets:
28
+
29
+
```c++
30
+
int getRbufSizePkts(int SRTO_RCVBUF, int SRTO_MSS, int SRTO_FC)
31
+
{
32
+
// UDP header size is assumed to be 28 bytes
33
+
// 20 bytes IPv4 + 8 bytes of UDP
34
+
const int UDPHDR_SIZE = 28;
35
+
const in pkts = (rbuf_size / (SRTO_MSS - UDPHDR_SIZE));
36
+
37
+
return min(pkts, SRTO_FC);
38
+
}
39
+
```
40
+
41
+
If the value of `SRTO_RCVBUF` in packets exceeds `SRTO_FC`, then it is silently set to the value in bytes corresponding to `SRTO_FC`.
42
+
Therefore, to set higher values of `SRTO_RCVBUF` the value of `SRTO_FC` must be increased first.
43
+
44
+
### Calculating Target Size in Packets
45
+
46
+
The minimum size of the receiver buffer in packets can be calculated as follows:
47
+
48
+
`pktsRBufSize = bps / 8 × (RTTsec + latency_sec) / bytePayloadSize`
49
+
50
+
where
51
+
52
+
- `bps` is the payload bitrate of the stream in bits per second;
53
+
- `RTTsec` is the RTT of the network connection in seconds;
54
+
55
+
- `bytePayloadSize` is the expected size of the payload of the SRT data packet.
56
+
57
+
If the whole remainder of the MTU is expected to be used, payload size is calculated as follows:
58
+
59
+
`bytePayloadSize = MSS - 44`
60
+
61
+
where
62
+
63
+
- 44 is the size in bytes of an **IPv4** header:
64
+
- 20 bytes **IPv4**
65
+
- 8 bytes of UDP
66
+
- 16 bytes of SRT packet header.
67
+
68
+
- `MSS` is the Maximum Segment Size (aka MTU); see `SRTO_MSS`.
69
+
70
+
### Calculating Target Size to Set
71
+
72
+
To determine the value to pass in `srt_setsockopt(..)` with `SRTO_RCVBUF`
73
+
the size in packets `pktsRBufSize` must be converted to the size in bytes
74
+
assuming the internal conversion of the `srt_setsockopt(..)` function.
75
+
76
+
The target size of the payload stored by the receiver buffer would be:
77
+
78
+
`SRTO_RCVBUF = pktsRBufSize × (SRTO_MSS - UDPHDR_SIZE)`
79
+
80
+
where
81
+
82
+
- `UDPHDR_SIZE` = 28 (20 bytes IPv4, 8 bytes of UDP)
83
+
- `SRTO_MSS` is the corresponding socket option value at the moment of setting `SRTO_RCVBUF`.
84
+
85
+
86
+
### Summing Up
87
+
88
+
89
+
```c++
90
+
91
+
auto CalculateTargetRBufSize(int msRTT, int bpsRate, int bytesPayloadSize, int msLatency, int SRTO_MSS, int SRTO_FC)
92
+
{
93
+
const int UDPHDR_SIZE = 28;
94
+
const int targetPayloadBytes = (msLatency + msRTT / 2) * bpsRate / 1000 / 8;
95
+
const int targetNumPackets = targetPayloadBytes / bytesPayloadSize;
96
+
const int targetSizeValue = targetNumPackets * (SRTO_MSS - UDPHDR_SIZE);
97
+
return {targetNumPackets, targetSizeValue};
98
+
}
99
+
100
+
// Configuring
101
+
102
+
const auto [fc, rcvbuf] = CalculateTargetRBufSize(msRTT, bpsRate, bytesPayloadSize, SRTO_RCVLATENCY, SRTO_MSS, SRTO_FC);
103
+
104
+
int optval = fc;
105
+
int optlen = sizeof optval;
106
+
srt_setsockopt(sock, 0, SRTO_FC, (void*) &optval, optlen);
107
+
108
+
optval = rcvbuf;
109
+
srt_setsockopt(sock, 0, SRTO_RCVBUF, (void*) &optval, optlen);
110
+
```
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4