September 9, 2022

Why a buffer is needed in the SRT Mini Server

As you know, our SRTMiniServer receives SRT streams, and outputs them in NDI and SDI format. An important requirement for such conversion is smooth playback, and synchrony between audio and video. To achieve this, our SRTMiniServer uses such a method as buffering. In this article we will try to explain what it is and what values to set for buffer.
Thus, when working with SRTMiniServer we are often asked how to fill in the buffer field.
First, we would like to explain what it is and why we need it in the first place.

The buffer helps to solve several problems, which will be discussed below.

Problem No. 1: Network fluctuation

In theory, all network packages should flow  equally between the two computers. However, in practice, of course, this is not the case. 

Data from the encoder is sent out uniformly, but as it crosses the Internet, it may arrive at the server at an erratic rate. A buffer is used to smooth this out. The buffer accumulates incoming packets and arranges them in an orderly manner. From the buffer, packages come out evenly again. 

Accordingly, if you are not sure about the quality of the internet connection between the encoder and the SRTMiniServer, you can set the start buffer value to a few seconds. A large start buffer will smooth out jumps in the internet connection, but the cost is that frames will appear on the output with a delay (equal to the length of the buffer).

Problem No. 2: Synchronisation of audio and video

Another task that the buffer solves is the synchronisation of audio and video. Because audio data is "lighter", it can reach the server faster than video data.

If we were to start playing all the data coming to the server as soon as it arrives (ASAP), the viewer would see an unpleasant mishmash of audio and video. The buffer is designed to make the playback smooth and the video and sound synchronised.
Demonstration of work without a buffer and with a buffer

How to Set the Starting Value

Suppose you set the start value to N ms. This means that the buffer will only release frames when it has accumulated N ms. By default, the start buffer is set to 100 ms. For example, at 25 fps, the buffer will begin to output frames as soon as it has accumulated 4 frames.

In most cases, we recommend using small values for the start buffer. However, if the communication between the encoder and the server jumps at times, you can set a large start value, e.g. 3000 ms. In this case, an accumulated buffer will help to smooth out short jumps in communication.

How to Set the Maximum Value

Obviously, if at some point a "crowd" of packets arrives at once, the amount of data in the buffer will increase dramatically. In addition, the more often such "bursts" occur, the bigger the buffer will grow. This means increased memory consumption.

In addition, a large buffer means that a newly arrived frame will only be displayed when its turn comes. Let's assume that at some point we have 3000 ms of data in the buffer. This means that a new frame which arrives in the buffer will take 3 seconds to reach the "viewer". Therefore, if you want to have "glass-to-glass" delay and you need RealTime - set maximum value of buffer, for example, 300 ms. Of course, in this case it is supposed that some frames will be dropped. If you do not need RealTime, you may set it to 3000 ms, for example.

By setting the maximum buffer value, you can automatically control the buffer size. For example, if the maximum value is 3000 ms, when this value is reached, all frames in the buffer will be destroyed.

You can use "zero" as the maximum buffer value to disable this behaviour. In this case, the buffer may grow uncontrollably, but you can always press the "Reset buffer" button to clear it.
auto reset counter
Important: do not set the maximum too close to the minimum. For example, specifying a buffer of 300-350 ms is a bad idea. Specify a maximum buffer no closer than 200 ms to the minimum, e.g. 300-500.

Buffer reset:

As we have already said, the buffer can proliferate. This usually happens when packets arrive very irregularly. If you realise that the glass-to-glass delay has increased, you can press the Reset buffer button. This will clear the queue for playback. 

If the buffer is set to 1000 ms for example - then the server will automatically press the Reset buffer button.
buffer reset button

Practical guidelines:

Case No. 1:
Good communication between the encoder and the server, and we need minimal glass-to-glass delay.
Tip: apply a buffer of 100 - 300 ms.

Case No. 2:
Communication between the encoder and the server is very unstable; we do not care about latency. However, the quality of playback is important.
Tip: apply a buffer of 3000 - 0 ms.

Case No. 3: 
Communication between encoder and server is very unstable, I want smooth playback with minimal delay.
Tip: it doesn't work like that.

Conclusion:

In this article, we have tried to explain the need for a buffer and further recommendations on how to set it up. However, we recommend to check the specific buffer values with test broadcasts.

Additionally:

  • Other articles of interest can be found here.

  • Download SRT Mini Server and our other products here.

  • Instructions for installation and use help.