Skip to content

libobs: End the stop of an output that never got a packet - #3764

Merged
vpacher merged 3 commits into
masterfrom
fix/3739-unstarted-output-stop
Nov 6, 2026
Merged

vpacher merged 3 commits into
masterfrom
fix/3739-unstarted-output-stop

Conversation

@vpacher

@vpacher vpacher commented Nov 6, 2026

Copy link
Copy Markdown
Member

Fixes #3739

What and why

The FFmpeg muxer output (ffmpeg_muxer, which the Source Record plugin uses) ends a stop only when a packet at or after the stop time arrives: ffmpeg_mux_stop() sets its stopping flag, and ffmpeg_mux_data() ends the data capture. The interleaver hands an output no packet until both its video and its audio encoder produced one. When the audio never comes (Source Record on a source whose audio has not started), the output gets no packet at all, its stop never ends, and obs_output_destroy() waits on the stopping event forever: OBS does not exit. Upstream 33.0.1 has the same hang.

  • struct obs_output gets a delivered_packet flag. It is set just before a packet reaches info.encoded_packet (the default callback, and the interleaver's hand-off in C and in its Rust port), and cleared when data capture begins.
  • obs_output_actual_stop(): when an encoded output without a stream delay is stopped and never got a packet, libobs ends its data capture after the output's stop(). A later end from the output is ignored by the existing guard.
  • The FFmpeg muxer then still holds the pipe of that start, so ffmpeg_mux_start_internal() closes it before it opens a new one.
  • The interleaver's fields struct gets a pointer to the flag, appended (no offset moves). NULL means "not tracked", as in the existing test_output_interleave stub, which does not change.

Risk: an encoded output that gets its first packet only after the stop is requested now ends at once instead of waiting for that packet. Such a recording had no data before the stop, so nothing is lost.

RED → GREEN

  • RED, the first commit: test_output_stop_without_packets, an output that stops like ffmpeg_muxer, with a raw video encoder and an audio encoder that produces packets or none, in a child process with a watchdog. On master (hybrid and C libobs): without audio the output gets 0 packets and is still active 3 s after the stop. With audio (control) it gets 110 packets, stops and is destroyed.
  • GREEN, the second commit: both cases pass on the C libobs and on hybrid.

Real app, Linux, Source Record 0.4.8 on an NDI source through DistroAV, record for 30 s and quit, 6 runs each:

Build Source Record started Quit hung
Upstream 33.0.1 1 of 6 every run where it did not start
master 3 of 6 every run where it did not start
This PR 2 of 6 0 of 6

Why Source Record starts late or not at all is a separate question (it also happens on upstream); this PR only makes a stop without packets end.

  • Rust: Tier 1 checks that the interleaver sets the flag before it hands the packet to the output; Tier 3 compares the flag and the fields layout with the C oracle.
  • Local gate: all Linux lanes passed (Tier 2 against hybrid and the C reference).
  • Windows (local MSVC build, hybrid and C reference): 1795 exports identical, 51 of 51 output, encoder, muxer and replay Tier 2 tests pass on both DLLs, 65 Rust interleave tests pass. The new cmocka test needs core video and runs on Linux only.
  • Test cost: the new cmocka test has two cases, each 1.5 s of capture in its own child process; the changed Rust tests are pure and start no threads.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 or updated
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: the C and the Rust change together)

🤖 Generated with Claude Code

vpacher and others added 3 commits November 6, 2026 16:15
The FFmpeg muxer output, which source-record uses, ends a stop only when a
packet at or after the stop time arrives. When its audio encoder never
produces a packet, the interleaver hands it none, the stop never ends, and
obs_output_destroy() waits on the stopping event forever: OBS does not
exit.

The test runs an output that stops like ffmpeg_muxer, with a raw video
encoder and an audio encoder that produces packets or none, in a child
process with a watchdog. RED on master (hybrid and C libobs): without
audio the output gets 0 packets and is still active 3 s after the stop;
with audio it gets 110 packets and stops and is destroyed.

Refs #3739.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The FFmpeg muxer output ends a stop only when a packet at or after the
stop time arrives. An output whose encoders never produce a packet (the
source-record plugin while its source's audio is pending) gets none, its
stop never ends, and obs_output_destroy() waits on the stopping event
forever: OBS does not exit.

Outputs now have a delivered_packet flag, set just before a packet reaches
info.encoded_packet (the default callback, and the interleaver's hand-off
in C and in its Rust port) and cleared when data capture begins. When an
encoded output without a stream delay is stopped and never got a packet,
obs_output_actual_stop() ends the data capture after the output's stop();
a later end from the output is ignored by the existing guard.

The FFmpeg muxer then still holds the pipe of that start, so its next
start closes it before it opens a new one.

test_output_stop_without_packets: without audio the output now stops and
is destroyed; with audio it stops as before. Rust: the interleaver's
fields carry the flag (appended, no offset moves), Tier 1 checks it is set
before the hand-off, Tier 3 compares it with the C oracle.

Fixes #3739.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=8e571495e6b272d224b2e4cbc8a86eefff305bbb secs=383 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793980187,"gate":"rust/all/fmt","host":"linux-x86_64","key":"191f07b201fdbc421500f87d3ff4c56511bd72a8cca13980856237fe846eb4b8","lane":"lint","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":85,"stamp":"10144e6172672eec5cf9d9281e59aa2d","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"191f07b201fdbc421500f87d3ff4c56511bd72a8cca13980856237fe846eb4b8","lane":"lint","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":85,"stamp":"e463fe343ca12ac925b063554d677530","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"6429dcc24ecc9e25d53593c8877b1b5973859c756fb3a04e34a57b7db90d7508","lane":"rust-test","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":94,"stamp":"ad58f3fa772a450f457acaf426789791","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":62,"stamp":"2ad37d158891dc0625a72f6234789862","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":62,"stamp":"41f73c883ba78996b5c9dde190c93a4c","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":62,"stamp":"9a20d6d3465c564d0ad6cafdd63f3ffd","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":62,"stamp":"6d41c16eabf0d8a8df3bd85f7ef1af19","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"50ec788d94730a0f7dc5b0565b9d91026720c93262a4b794f74dc42caab93198","lane":"tier2-linux","parents":["3e1da00595c32a37d52e11a23b235ae4d9a63399"],"secs":383,"stamp":"8ec5bc0467c61e6764ee707242b2e9c5","tree":"8e571495e6b272d224b2e4cbc8a86eefff305bbb","v":1,"via":"run"}
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=893902ba676e26066ba93603741e60b93d5cef4b secs=33 lanes=lint:run,rust-test:reused@6429dcc24ecc,cross:reused@b9221e399036,tier2-linux:reused@50ec788d9473,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793980741,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e4967154eb7e8ef3a4e2293864763166ffb83692adb127b950f3da4877e9b385","lane":"lint","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":33,"stamp":"1c7da6251ca7be967bae9af460a1c5e9","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"run"}
Ci-Attestation: {"at":1793980741,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e4967154eb7e8ef3a4e2293864763166ffb83692adb127b950f3da4877e9b385","lane":"lint","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":33,"stamp":"e0dd2b9087661a1c8f42f6253d4229e7","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"run"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"6429dcc24ecc9e25d53593c8877b1b5973859c756fb3a04e34a57b7db90d7508","lane":"rust-test","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":null,"stamp":"4bdc5578433a19e62f9fa280b0136dd9","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"reused"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":null,"stamp":"e2f00ce84759a6520e271a1887773429","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"reused"}
Ci-Attestation: {"at":1793980187,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":null,"stamp":"6f2975c26ec4b9cbc9d51ee7188eba8c","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"reused"}
Ci-Attestation: {"at":1793980187,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":null,"stamp":"83dd6084033fa0bc7d9fa7758a4b2cb1","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"reused"}
Ci-Attestation: {"at":1793980187,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"b9221e3990367419c63d158601bba79c7f87b4739b38aca6faf0dda54ec6a100","lane":"cross","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":null,"stamp":"f2ea88ba807a13862fb7871d40fa952d","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"reused"}
Ci-Attestation: {"at":1793980187,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"50ec788d94730a0f7dc5b0565b9d91026720c93262a4b794f74dc42caab93198","lane":"tier2-linux","parents":["6931637cc1400bbf075de9230de7bf0860e06e34"],"secs":null,"stamp":"999688c6e9f3d0c945199f71c4742808","tree":"893902ba676e26066ba93603741e60b93d5cef4b","v":1,"via":"reused"}
@vpacher
vpacher requested a review from zackees as a code owner November 6, 2026 16:00
@vpacher
vpacher enabled auto-merge November 6, 2026 16:01
@vpacher
vpacher added this pull request to the merge queue Nov 6, 2026
Merged via the queue into master with commit 5f71441 Nov 6, 2026
39 of 40 checks passed
@vpacher
vpacher deleted the fix/3739-unstarted-output-stop branch November 6, 2026 16:30
@rdoupe rdoupe mentioned this pull request Nov 6, 2026
7 tasks done
vpacher added a commit that referenced this pull request Nov 13, 2026
…ring its destroy (#3799)

The end of capture added for #3764 ran on every stop of an encoded output
that never got a packet, also on the second stop that obs_output_destroy()
makes when the output still counts as active while its end thread runs.
That call found the capture already ended and sent the stop signal again.
Older source-record versions free their stop handler's data on the first
stop signal and never disconnect it, so the second one ran the handler on
freed data: a double free, and OBS aborted right after a recording
started (the reporter's backtrace in #3799).

The end now runs only while the capture is still active; the first stop
still ends a capture that never got a packet (#3764).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amsterdamboomer pushed a commit to amsterdamboomer/obs-studio that referenced this pull request Nov 21, 2026
…ring its destroy (obs-rust#3799) (obs-rust#4843)

* test: a force stop and a release right after its stop signal send stop once (obs-rust#3799)

Older source-record versions force-stop their recording output, release
it from their stop handler and free the handler's data there, without
disconnecting it. When the release finds the output still active, the
destroy stops it again; for an output that never got a packet the end
added for obs-rust#3764 then sends a second stop, the handler runs on freed
data and glibc aborts (the reporter's backtrace). The new case connects
a stop handler that stays connected, force-stops an output that never
got a packet, releases it as soon as the first stop arrived, and
expects one stop signal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* libobs: send an output's stop signal once when it is stopped again during its destroy (obs-rust#3799)

The end of capture added for obs-rust#3764 ran on every stop of an encoded output
that never got a packet, also on the second stop that obs_output_destroy()
makes when the output still counts as active while its end thread runs.
That call found the capture already ended and sent the stop signal again.
Older source-record versions free their stop handler's data on the first
stop signal and never disconnect it, so the second one ran the handler on
freed data: a double free, and OBS aborted right after a recording
started (the reporter's backtrace in obs-rust#3799).

The end now runs only while the capture is still active; the first stop
still ends a capture that never got a packet (obs-rust#3764).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Quitting the GUI does not end the process on Linux

1 participant