Repository navigation
libobs: End the stop of an output that never got a packet - #3764
Merged
Merged
Conversation
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
enabled auto-merge
November 6, 2026 16:01
7 tasks done
This was referenced Nov 7, 2026
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]>
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 #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, andffmpeg_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, andobs_output_destroy()waits on the stopping event forever: OBS does not exit. Upstream 33.0.1 has the same hang.struct obs_outputgets adelivered_packetflag. It is set just before a packet reachesinfo.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'sstop(). A later end from the output is ignored by the existing guard.ffmpeg_mux_start_internal()closes it before it opens a new one.test_output_interleavestub, 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
test_output_stop_without_packets, an output that stops likeffmpeg_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.Real app, Linux, Source Record 0.4.8 on an NDI source through DistroAV, record for 30 s and quit, 6 runs each:
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.
Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag changes)🤖 Generated with Claude Code