roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.02k stars 203 forks source link

Implement warmup phase in watchdog #657

Closed gavv closed 5 months ago

gavv commented 7 months ago

Problem

Watchdog class monitors audio stream and terminates session if it detects that there is no playback during specified timeout, or there is constant stuttering.

There is one problem with current implementation. Pipeline design implies that at the very beginning of the session, there is no playback (all samples are zero) until the initial buffer of N samples is accumulated, where N is target latency.

It means that if watchdog no_playback timeout (aka blank timeout) is smaller than the target latency, then it's always triggered at start, and the session is always terminated.

Solution

The fix is simple: at the very beginning, watchdog should enter "warmup" phase when timeouts are not triggered.

Warmup phase should end when:

In roc_pipeline, we should set watchdog warmup parameter equal to the configured target latency.

Testing

Before the fix, in roc-recv, if --no-play-timeout is smaller than --sess-latency, the session will be constantly terminated and restarted. After the fix, it should work fine.

E.g.:

roc-send -vv -s rtp+rs8m://localhost:10001 -r rs8m://localhost:10002 -i file:test.wav
roc-recv -vv -s rtp+rs8m://localhost:10001 -r rs8m://localhost:10002 --no-play-timeout 100ms --sess-latency 1000ms

Before the fix, there is no playback, and you will see frequent messages like this:

14:29:38.699 [2784693] [inf] roc_pipeline: [receiver_session_group.cpp:259] session group: removing session
14:29:38.710 [2784693] [inf] roc_pipeline: [receiver_session_group.cpp:228] session group: creating session: src_addr=[::1]:42323 dst_addr=[::1]:10001

We also need to update unit tests:

zann136 commented 6 months ago

Hey! I'd like to work on this issue. Are you still looking for help regarding it?

gavv commented 6 months ago

Yes. You're welcome, thanks!

gavv commented 5 months ago

Landed!