Skip to content

obs-ffmpeg: Let a stop end an SRT listener's wait for its caller - #1422

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/srt-listener-stop
Oct 18, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/srt-listener-stop

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

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/RIST URLContext without an interrupt_callback. libsrt_network_wait_fd_timeout() checks that callback between its 100 ms polls, and an SRT listener has no listen_timeout by 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, including ffmpeg_mpegts_destroy() at quit, so each of them waited as long.
  • A stop now sets abort_connect before 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).
  • When a stop ended the connect, 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.
  • Not in this PR: stopping before the first caller has ever connected. The stream button and obs-websocket's StopStream don't offer a stop while any stream is still connecting. That's a frontend change with its own design, because RTMP's stop also waits for its connect. Quitting in that state works now.

Headless (private Xvfb, private D-Bus, fresh HOME), driven over obs-websocket, with ffmpeg as the SRT caller:

Build Case Result
v0.1.0-beta.20261018 AppImage listener nobody calls, SIGTERM still running 15 s later
master 28fdf7e caller left → RECONNECTING, StopStream still reconnecting 10 s later
master 28fdf7e listener nobody calls, SIGTERM still running 30 s later
This branch caller left → RECONNECTING, StopStream stopped, the UI still answers
This branch listener nobody calls, SIGTERM quits, clean shutdown in the log

RED → GREEN

  • RED commit: 3236f9d test: Add failing Tier 4 phase for stopping an SRT listener. run_tier4.py --only srt (also part of the full run) streams to srt://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 s and srt-quit:OBS quits on SIGTERM while the listener waits.
  • GREEN: f13ef5d. The srt phase passes 9 of 9, 3 of 3 runs. The full Tier 4 suite: 208/208 checks, 147/147 documented request types; after the rebase onto frontend: Queue scene changes that scripts make from a timer #1417, 209/212 (the 3 misses are frontend: Queue scene changes that scripts make from a timer #1417's Lua phase, which fails by design in this build without scripting). 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).
  • Real app: the Tier 4 phase above is the real app.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Encoding, streaming and recording)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite

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

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: LGTM.

  • The interrupt callback is the right hook: libsrt_network_wait_fd_timeout() checks ff_check_interrupt() between its 100 ms polls, and nothing else can end a listener with no listen_timeout.
  • Order is right: abort_connect is 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.

@zackees
zackees enabled auto-merge October 18, 2026 17:11
@zackees
zackees added this pull request to the merge queue Oct 18, 2026
Merged via the queue into obs-rust:master with commit b96f4ed Oct 18, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: obs-ffmpeg: an SRT listener waiting for a caller can't be stopped, and OBS can't quit (upstream #12250)

2 participants