Repository navigation
obs-ffmpeg: Let a stop end an SRT listener's wait for its caller - #1422
Merged
Merged
Conversation
The SRT and RIST URLContext had no interrupt callback, and an SRT listener has no listen timeout by default, so its start thread waited for a caller for as long as it took. Every stop joins that thread first: Stop Streaming while a listener waited for its caller to come back never stopped the stream, and destroying the output at quit never returned. A stop now sets abort_connect before it joins, and the interrupt callback returns it, so the wait ends within 100 ms. A connect that a stop ended does not signal a connect failure: while reconnecting, libobs would take that as a reason to reconnect again. Fixes obs-rust#1421
rdoupe
force-pushed
the
fix/srt-listener-stop
branch
from
October 18, 2026 17:08
0146535 to
f13ef5d
Compare
zackees
approved these changes
Oct 18, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: LGTM.
- The interrupt callback is the right hook:
libsrt_network_wait_fd_timeout()checksff_check_interrupt()between its 100 ms polls, and nothing else can end a listener with nolisten_timeout. - Order is right:
abort_connectis set before the start thread is joined (outside the mutex, as before), and every start/reconnect attempt clears it first. libobs stops the reconnect thread before it calls the output's stop, so a reconnect can't clear the flag behind a stop. - Not signalling the failure in
set_config()on an aborted connect avoids a second stop signal and an extra reconnect. - RED (Tier 4
--only srt) then GREEN; it skips cleanly without an SRT-capable ffmpeg; ledger line present.
Nit, no change needed: abort_connect stays true after a stop until the next start, which is harmless since nothing connects in between.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1421
What and why
Stop Streaming now stops an SRT listener stream that is waiting for its caller to come back, and OBS quits while a listener waits for a caller. Before, the stream never stopped, and OBS never finished quitting (upstream obsproject/obs-studio#12250, reported by Meekel, closed as won't fix).
connect_mpegts_url()allocated the SRT/RISTURLContextwithout aninterrupt_callback.libsrt_network_wait_fd_timeout()checks that callback between its 100 ms polls, and an SRT listener has nolisten_timeoutby default, so the start thread waited for a caller however long that took.ffmpeg_mpegts_stop_internal()joins the start thread before it stops anything. It is behind every stop, includingffmpeg_mpegts_destroy()at quit, so each of them waited as long.abort_connectbefore the join, and the new interrupt callback returns it. The waiting listener, or a caller still connecting, gives up within 100 ms. Each start clears the flag (the first start and every reconnect attempt).set_config()no longer signals the connect failure. The stop signals the stop. During a reconnect, libobs takes a failure code as a reason to reconnect again, so the stop would not have ended the reconnect loop.Headless (private Xvfb, private D-Bus, fresh HOME), driven over obs-websocket, with ffmpeg as the SRT caller:
RED → GREEN
test: Add failing Tier 4 phase for stopping an SRT listener.run_tier4.py --only srt(also part of the full run) streams tosrt://127.0.0.1:P?mode=listener. An ffmpeg caller connects and is killed. Once OBS reports reconnecting, the test sends StopStream and expects the stream stopped within 10 s, with the UI thread still answering. Then a new OBS streams to a listener nobody calls and gets SIGTERM; it must quit with a clean shutdown. The reconnect case needs an ffmpeg with the srt protocol, and it is skipped, with a message, without one. On master, 2 of 9 checks fail:srt:the stream stops within 10 sandsrt-quit:OBS quits on SIGTERM while the listener waits.ctest -j4(C lane): 306/306, none skipped. Our SRT release checks against this build: 51-53, 56-58 and 70 find no problem besides the AppImage-only "libsrt loaded from outside the AppDir". 55 now quits on SIGTERM with no caller (1.2 s) and stops after a refused caller (STOPPED after 0.3 s); its no-caller StopStream case is the follow-up above. 54 fails as on the 20261018 release. The change is in obs-ffmpeg only, which is the same C code in both lanes, so I built the C lane, with the native SRT/RIST output (ENABLE_NEW_MPEGTS_OUTPUT, as on CI's Ubuntu builds).Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Encoding, streaming and recording)