Repository navigation
obs-output: Port the output stop decisions - #2536
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The decisions of obs_output_stop(), end_data_capture_thread() and obs_output_end_data_capture_internal() move to libobs/obs-output-stop.c.h, as seven functions on plain values declared in the new libobs/obs-output-stop.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - _encoded() (OBS_OUTPUT_ENCODED: obs_output_stop()'s delayed stop, the encoders or the raw video and audio in the end-capture thread, the unstarted encoders' shutdown); - _delay_on() (active_delay_ns is not 0: the delayed stop, the process_delay() callback and the delay cleanup); - _has_video() and _has_audio() (which encoders or raw connections stop; the frame log); - _service() (the service is deactivated); - _end_delay() (delay_restart_refs is 0: the delay ends; otherwise a restart keeps it); - _thread_failed() (pthread_create() did not return 0: the unstarted shutdown is dropped, or the end-capture thread runs inline). Two rules were already ported, so their callers ask them: end_data_capture_thread()'s interleave test is obs_output_raw_audio_interleave(), the test hook_data_capture() asks for the same callback, and stop_raw_audio()'s mix test is obs_output_raw_audio_mix_on(), start_raw_audio()'s (#2457). The first mixer was already obs_output_first_mixer(). obs-output-raw-audio.h notes the new callers. One function per decision, asked where the C made it, so every read stays where it was. The plan's routes (stop_route, actual_stop, end_route and signal_stop_clears over the atomics, thread_stops over the flags and active_delay_ns) would load an atomic where the C's && and early returns do not, or load one once for a whole function that another thread writes between the tests: reconnecting is loaded twice in obs_output_actual_stop() and obs_output_stop(), and active_delay_ns twice in end_data_capture_thread() while the encoders' callbacks still write it. So the single-field tests stay C in their order: context.data, active, reconnecting, the stopping event, force, delay_active, delay_capturing, data_active, the end-capture thread's flag, raw_audio2 and signal. Nothing is left to decide in obs_output_force_stop(), obs_output_actual_stop() or obs_output_signal_stop()'s stop branch (single-field tests only), so they are unchanged. C keeps every atomic load and store, the stopping event, the unpause, the reconnect thread's join, info.stop, obs_output_end_data_capture(), obs_output_delay_stop(), obs_encoder_stop(), obs_encoder_shutdown_unstarted(), stop_raw_video(), audio_output_disconnect(), obs_service_deactivate(), obs_output_cleanup_delay(), log_frame_info(), the caption frees under their mutex, the keyframe tracking clear, the joins, pthread_create(), the stop parameters copied before a thread starts (#2086, #2098), the reconnect policy, every signal and every log. No read changes: each new call reads the field the old test read, in the same place and order. Checked in a scratch harness (not committed). It compiles origin/master's obs_output_actual_stop(), obs_output_stop(), obs_output_force_stop(), stop_audio_encoders(), stop_video_encoders(), stop_raw_audio(), end_data_capture_thread(), shutdown_unstarted_encoders() and its thread, obs_output_end_data_capture_internal(), obs_output_end_data_capture() and obs_output_signal_stop(), with their flag, atomic and join helpers and get_first_mixer(), verbatim, and this branch's with the moved file, obs-output-raw-audio.c.h and obs-output-video-checks.c.h, with every read of info.flags, active_delay_ns, mixer_mask, context.data, raw_audio2 and reconnect_thread_active and every write of stop_code rewritten the same way into a logged access, over a stand-in output. It logs every atomic load, store, exchange, increment and decrement (with the field and value), every stopping and reconnect event test, reset and signal, the unpause, every join and pthread_create() (with its result), info.stop, every lock and unlock, bfree(), the keyframe clear, obs_output_valid(), the delayed stop, each encoder stop (with its callback), each unstarted shutdown, the raw video stop, each audio disconnect (with its mix), the deactivation, the delay cleanup, the frame log, the stop parameters, every signal and every log, in order. Another thread flips one of the atomics, the stopping event, active_delay_ns, the restart refs or reconnect_thread_active, or runs a created thread, at random between events. - Inputs: all 16 combinations of the four flags, with and without high bits, context.data and raw_audio2, each atomic set and clear, restart refs of 0, 1, 2, -1, LONG_MIN and LONG_MAX, delays of 0, 1, 10^9 and UINT64_MAX, mixer masks with and without high bits, encoders and caption tracks present or not, every result of the valid check, can_reconnect() and pthread_create(), forced or not, signalled or not, six stop codes; one to six calls in a row, the created threads run at the end of a call or in the middle of the next. - 2,900,000 runs (GCC and Clang -O2, 1,000,000 each; GCC -O0, 500,000; ASan with UBSan under GCC -O0 and Clang -O2, 200,000 each) give equal events and an equal end state (every atomic, both events, the stop code, the thread, the keyframe tracking and the caption tracks): 204,669,941 events. - Every branch of origin/master's functions is taken both ways (gcov, 130 of 130). - 21 deliberately broken moves were planted and 20 fail it: the encoded, video, audio and service rules on the wrong flag or inverted, the delay rule > 1, the end-delay rule inverted or for positive counts only, the thread rule for negative results only, OBS_OUTPUT_STOP_ENCODED on the wrong bit, active_delay_ns read before the flags in the delayed stop, the interleave asked with video twice, the callback ignoring the delay, the delay cleanup on the encoded flag, the next mix disconnected, the encoded flag read before active in the unstarted shutdown, the end delay inverted at its call, the frame log on the audio flag, the inline fallback inverted, the unstarted thread's result ignored, and the deactivation after the delay cleanup. The one that passes reads has_audio before has_video: two reads of info.flags, which is set when the output is created and never written again, so it is equivalent. git blame on the moved lines shows upstream commits (0538865, 29e849e, 3869cb8, 645e31f, a1fbf10, b8a3ae1, d314d47, d7db0b8) and this fork's unstarted encoder shutdown (7041590). The four flags are copied into the header, so it needs no core header; obs-output.c.h checks them with _Static_assert. The new file joins libobs.core-output, just before obs-output.c.h, with libobs.pch.h, which includes the new header; source-sets.json lists it. docs/rust-port/naming.md maps the file to rust/obs-output. The exported symbol sets are unchanged (1766) on the hybrid and C reference libobs, and identical; the seven functions are local. Refs #2535.
test_output_stop_steps compiles libobs/obs-output-stop.c.h, libobs/obs-output-raw-audio.c.h (whose interleave and mix tests the end-capture thread and stop_raw_audio() ask) and libobs/obs-output-video-checks.c.h (the first mixer) with ASan and UBSan, and calls only their functions through their headers. Six cases on the functions: - the copied flags (OBS_OUTPUT_VIDEO, _AUDIO, _ENCODED, _SERVICE); - the encoded, video, audio and service rules over every low 16-bit flag word with four high words (each looks at its own bit only); - the running delay, for any active_delay_ns that is not 0; - the end of the delay, only for no restart reference (a negative count keeps it too: characterized, not endorsed, never reached); - the thread creation failure, for any result that is not 0; - the shared rules at these callers' values: the interleave over both flags, each mix's bit below six mixes, the first mixer (0 for none). The bodies of obs_output_stop(), obs_output_force_stop(), obs_output_actual_stop(), stop_raw_audio(), end_data_capture_thread(), shutdown_unstarted_encoders_thread(), obs_output_end_data_capture_internal(), obs_output_end_data_capture() and obs_output_signal_stop() are also copied onto a stand-in output (no thread, lock, service or encoder; their results are given, a created thread runs when the case says, and every call, event, signal and warning is recorded), to pin end to end in 13 cases: - the stop of a stream and a raw output (the stop code left for the plugin, still active); invalid, no data, neither active nor reconnecting, already stopping; data_active, delay_active and delay_capturing not changing the route; - the delayed stop of an encoded output, even while stopping; a raw output with active_delay_ns stopping at once (characterized, not endorsed); reconnecting coming first; - a reconnecting output stopped with data (with and without its thread to join), without data (refused, and forced: the stop signalled here), and with a delay active (not "was reconnecting": the forced stop clears the delay, then ends the capture); - the forced stop when stopping and not, of an inactive output, and invalid; - the not-forced refusal while stopping; the caption tracks freed; - the forced stop of a delayed output that is capturing (the plugin's stop after the end) and is not, not forced, and with data not active; - the end before the capture began: the code copied first, the last thread joined, the unstarted encoders shut down on a thread for an encoded output only, none while one is still ending or the output is active, the creation failing; without the end signal; invalid; - the end of a delay with 0, 1 and -1 restart references; - the full end of a stream (the frame log, the join, the code copied before the thread, the signal after; the thread's work), without the signal, of an audio-only output, and the inline fallback; - each callback (delay, interleave, default), empty slots, an encoded output with neither flag (characterized, not endorsed); the raw video and audio, each mix with raw_audio2, the first mixer without it, and a raw output's service and delay cleanup (characterized, not endorsed); - the stop signal without a reconnect (a delay, delay_capturing and reconnecting cleared first) and with one (a restart reference taken, no stop signal), a stream that never connected, invalid; - a stop then the end and its thread, a second stop while stopping and a forced one after it, an end before the last thread ran, and a delayed stop then the delay's end. It is in the native test graph, in name order, with the three headers as watch inputs, and links libm off MSVC. No assert_in_range or fail_msg, so it builds with cmocka 1.x and 2.x, and no comparison between two enum types (MSVC C5287). The real-libobs tests test_output_end_capture_thread_join, test_output_deactivate_state, test_null_output_stop_thread, test_ffmpeg_output_stop, test_ffmpeg_output_drain, test_encoder_error_stop, test_replay_buffer_pause_stop, test_output_delay_e2e, test_output_failed_start_encoders, test_recording_shutdown and test_pthread_init_failures cover the callers. Refs #2535.
RED for the port of libobs/obs-output-stop.c.h to a new output_stop module of rust/obs-output, next to output_start and stop_stats. The safe core is a stub (todo!()): encoded(), delay_on(), has_video(), has_audio(), service(), end_delay() and thread_failed(), with the four flags (video_checks'). It re-exports raw_audio's interleave() and mix_on() and video_checks' first_mixer(), the callback, mix and first mixer rules the callers share, already ported. tests/output/output_stop.rs ports test_output_stop_steps 1:1: its 19 cases under the same names (steps_*), in the same order, with the same values and expectations, the characterized-not-endorsed cases included, the stand-in output and its copies of obs_output_stop(), obs_output_force_stop(), obs_output_actual_stop(), stop_raw_audio(), end_data_capture_thread(), shutdown_unstarted_encoders_thread(), obs_output_end_data_capture_internal(), obs_output_end_data_capture() and obs_output_signal_stop() written in Rust over the core. Edge cases (edge_*) check the core against the origin/master expressions inline: every low 16-bit flag word under 16 high words; every restart count and thread result from -1,000 to 1,000 and the extremes; every delay to 100,000 and the top 1,000; every mixer mask to 4,096 and three wide ones; the stand-in through eleven callers (each followed by its created thread) for every low flag word, each of eight atomics and the stopping event set and clear, a restart reference or none, a delay or none and each of eight inputs changed alone (294,912 outputs); and proptests (4,096 cases each) of every decision over full-range values and of the stand-in over sequences of up to eleven calls, with another thread flipping the atomics, the stopping event, the delay, the restart refs and the call results, or running the created thread, between them. soldr cargo test -p obs-data --test obs-tests-core -- output::output_stop passes 5 of 25 (the constants, the shared rules and the two cases whose paths ask no new rule) and fails 20 with "not yet implemented". Refs #2535.
Ports libobs/obs-output-stop.c.h, the output stop and end-capture decisions, to the output_stop module of rust/obs-output. obs-output.c.h stays C around it: obs_output_valid(), the context.data, raw_audio2, signal and force tests, every atomic load and store (active, data_active, reconnecting, starting, delay_active, delay_capturing, delay_restart_refs and the end-capture thread's flags) and the stopping event test where they always were, in their && order, the unpause, the event resets and signals, the reconnect thread's join, info.stop, obs_output_end_data_capture(), obs_output_delay_stop(), the encoder stops and shutdowns, stop_raw_video(), audio_output_disconnect(), obs_service_deactivate(), obs_output_cleanup_delay(), log_frame_info(), the caption frees under their mutex, the keyframe tracking clear, the joins, pthread_create(), the stop parameters copied before a thread starts, the reconnect policy, every signal and every log. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/output_stop.rs): - encoded(): OBS_OUTPUT_ENCODED is in the flags (the delayed stop, the encoders or the raw connections, the unstarted encoders' shutdown); - delay_on(): active_delay_ns is not 0 (the delayed stop, the process_delay() callback, the delay cleanup); - has_video() and has_audio(): OBS_OUTPUT_VIDEO, OBS_OUTPUT_AUDIO; - service(): OBS_OUTPUT_SERVICE (the deactivation); - end_delay(): the loaded restart count is 0; - thread_failed(): pthread_create() did not return 0; - interleave() and mix_on() re-exported from raw_audio and first_mixer() from video_checks: end_data_capture_thread(), stop_raw_audio() and get_first_mixer() call those shims, so they share one implementation. The flags are video_checks'. The module denies clippy's arithmetic, as, indexing, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state, takes no lock and does not divide. Shims (src/ffi/output_stop.rs): the seven functions keep the C signatures; the restart count comes in as c_long (32 bits on Windows) and is widened to i64, the thread result as c_int. No pointer crosses. No intentional differences. C side: the file leaves libobs.core-output for its own group, libobs.ported-output-stop (LIBOBS_PORTED_SOURCES), whose PCH is only obs-output-stop.h; libobs.pch.h keeps the header for obs-output.c. The functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust already links the crate's ffi. ci/test_ported_sources.py checks the group on every host. The exported symbol sets are unchanged (1766) on the hybrid and C reference libobs, and identical, and the seven functions are local in each; the hybrid libobs has no C object for the group. test_output_stop_steps still compiles the C file into itself, unchanged. It has no _rust variant, as for test_output_start_steps: the shims' archive member also holds the rest of obs-output, which needs libobs's hidden seams and obs-util, so it does not link on its own. Its tests.d file says so. soldr cargo test -p obs-data --test obs-tests-core -- output::output_stop passes 25 of 25. Through ctest (private Xvfb and D-Bus, own HOME and runtime directory, no sound), the full suite passes against the hybrid libobs and the C reference libobs, 582 of 582 each, the same 3 skipped on each (a PulseAudio default sink and the v4l2 vivid module, absent here). Among them test_output_stop_steps, test_output_end_capture_thread_join, test_output_deactivate_state, test_null_output_stop_thread, test_ffmpeg_output_stop, test_ffmpeg_output_drain, test_encoder_error_stop, test_replay_buffer_pause_stop, test_output_delay_e2e, test_output_failed_start_encoders, test_recording_shutdown, test_pthread_init_failures, test_output_start_steps and test_output_raw_audio_steps. Refs #2535.
Tier 3 for the output_stop port. The oracle (rust/obs-c-oracle/oracle/output_stop.c) compiles the unchanged libobs/obs-output-stop.c.h with its seven functions renamed to oracle_*, plus its four flags and the widths of long and int, bound in src/output_stop.rs. Nothing in it divides. The interleave and mix oracles are output_raw_audio's and the first mixer's output_video_checks'. tests/output/output_stop_parity.rs compares the oracle, the shims and the core exactly, all three sides: - the four flags, sizeof(long) (32 bits on Windows: the shim takes c_long and widens it) and sizeof(int); - the four flag rules over every low 16-bit flag word under 16 high words and a stride through all of u32; - the delay over 0 to 1,000,000, the top 100,000, a stride through all of u64, every power of two and a stride of multiples of 2^32 (not 0, with the low 32 bits clear); - the restart count over -100,000 to 100,000, the 100,000 values at each extreme of long and a stride through all of it; - the thread result over -100,000 to 100,000, both ends of int and a stride through all of it; - the callers on test_output_stop_steps' stand-in output (shared with Tier 1), on the oracle's gates and on the shims: eleven callers, each followed by its created thread, for every low flag word under two high words, each of eight atomics and the stopping event set and clear, a restart reference or none, a delay or none and each of eight inputs changed alone (589,824 outputs), comparing the record and the end state; - proptests (20,000 cases each) of every decision over full-range values and of the stand-in over sequences of up to fifteen calls, with another thread flipping the atomics, the stopping event, the delay, the restart refs and the call results, or running the created thread, between them. No input is excluded: nothing in the C divides or overflows, and the mix test is asked only below six, as stop_raw_audio() asks it. A restart count past a 32-bit long is passed to the C and the shim at the nearest end, which keeps "not 0". The proptests keep no regression files (failure_persistence None), as the start parity runners do. Mutation check (once, not committed): 20 mutants, 13 in the core and 7 in the shims. mutant Tier 1 Tier 3 encoded: == 12 4 encoded: the video flag 9 4 OBS_OUTPUT_ENCODED from the service flag 6 5 delay_on: > 1 5 2 delay_on: always 9 3 has_video: the audio flag 8 4 has_audio: the video flag 7 4 service: == 9 4 service: the encoded flag 8 4 end_delay: <= 0 5 3 end_delay: != 8 4 thread_failed: < 0 7 4 thread_failed: never 7 4 shim encoded inverted 0 4 shim delay_on: the low 32 bits only 0 1 shim has_video asks has_audio 0 4 shim has_audio asks has_video 0 4 shim service: flags >> 1 0 4 shim end_delay: positive only 0 3 shim thread_failed inverted 0 4 (failing tests per tier.) Tier 1 kills all 13 core mutants and Tier 3 all 20. The low-32-bit shim first survived Tier 3; the powers of two and the multiples of 2^32 in the delay inputs were added for it. soldr cargo test -p obs-data --test obs-tests-core -- output::output_stop passes 33 of 33 (25 Tier 1, 8 Tier 3). Refs #2535.
rust/README.md gets the row for libobs/obs-output-stop.c.h (obs-output::output_stop), after output_start's: what moved, the interleave, mix and first mixer rules shared with raw_audio and video_checks, what stays C and why (every atomic and the stopping event loaded where they always were, the single-field tests in their && order, the three functions left unchanged), the characterized-not-endorsed behaviours (a negative restart count keeping the delay, a raw output with active_delay_ns stopping at once and cleaning the delay up, an encoded output with neither flag stopping no encoder, a forced stop of an inactive output calling info.stop) and the tests that cover it; the obs-output crate row names the file. The crate's Cargo description and lib.rs named the module in the port commit, and docs/rust-port/naming.md maps the file (the move commit). rust/obs-c-oracle/benches/port_comparison/output_stop.rs, in the sorted module list, runs 1024 rounds over the flag words of a stream, a recording, a raw video and a raw AV output with delays, restart counts, thread results and mixer masks, asking every decision obs_output_stop(), obs_output_end_data_capture_internal(), end_data_capture_thread() and stop_raw_audio() ask, in their order, on the shims and on the oracle, and checks both checksums match; it allocates nothing. Release, x86_64 Linux, GCC, median (load average about 2): Rust 11.97 us, C 11.67 us (1.03x), about 12 ns a round, next to an encoder stop, a thread creation or a single signal. The port changes nothing a user can see, so docs/features.md has no line. Fixes #2535. Local-Gate: v1 tree=77f3d243bf420ee69d5e95cb6146969b8cbbd5b0 secs=2935 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run Ci-Attestation: {"at":1793060878,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f354ddaafb1c15220eefabf7ae947cdbbb8c4645965c892be853a458f5ef16bd","lane":"lint","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":55,"stamp":"e4bbf2bdbc8d4c1b7547c5965b53d0c2","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f354ddaafb1c15220eefabf7ae947cdbbb8c4645965c892be853a458f5ef16bd","lane":"lint","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":55,"stamp":"0d6b01e784ea3654ab7866f721bf3504","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"41d224f892012bab2557b4b451abce1d3d00fe9f9fdaa5a007c848b652cb0219","lane":"rust-test","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":225,"stamp":"1bb6727794422645927ea85f1b4b6b11","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"68304326bb180d3143006b4aeb0097fb","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"f81377b13bc7c6a0c2e134dea1cf15b5","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"9e47d3d83c06a4668a89cbc83890f62a","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"0a230a5fd6b21acbd36130c4de2dfd47","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"} Ci-Attestation: {"at":1793060878,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a8bb094345e54633d203f45ae83b9a8068a28660e8cdcf9b6cd0b12162628f15","lane":"tier2-linux","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":2568,"stamp":"e00d9c45cd138cbd539e6fa2dc570b83","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
rdoupe
force-pushed
the
fix/rust-port-output-stop-and-end-ca-182
branch
from
October 27, 2026 00:28
abaf419 to
18809e1
Compare
rdoupe
marked this pull request as ready for review
October 27, 2026 00:44
Collaborator
Author
|
Handed off to the coordinator |
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 #2535
What and why
Ports the decisions of the output stop and end-capture path of
libobs/obs-output.c.htorust/obs-output, as a new moduleoutput_stop, next tooutput_startandstop_stats. Every stream, recording, replay buffer and virtual camera stop passes through these, and so does every reconnect and every output that stops before its capture began (a stream that never connected):obs_output_stop(): the delayed stop (an encoded output with a delay running);end_data_capture_thread(): which encoders or raw connections stop, theprocess_delay()callback and the delay cleanup, and the service deactivation;obs_output_end_data_capture_internal(): the unstarted encoders' shutdown, whether restart references keep the delay, the frame log, and the inline fallback when a thread cannot be created (both threads).Three rules are reused, not copied. The end-capture thread's interleave test is
obs_output_raw_audio_interleave(), the testhook_data_capture()asks for the same callback;stop_raw_audio()'s mix test isobs_output_raw_audio_mix_on(),start_raw_audio()'s (#2457); and the first mixer was alreadyobs_output_first_mixer().output_stopre-exports them, andobs-output-raw-audio.hnotes the new callers.One function per decision, asked where the C made it. Seven functions cross the C ABI:
obs_output_stop_encoded(),_delay_on(),_has_video(),_has_audio(),_service(),_end_delay()and_thread_failed(). The plan's routes (stop_route,actual_stop,end_routeandsignal_stop_clearsover the atomics,thread_stopsover the flags andactive_delay_ns) would load an atomic where the C's&&and early returns do not, or load one once for a whole function that another thread writes between the tests:reconnectingis loaded twice inobs_output_actual_stop()and inobs_output_stop(), andactive_delay_nstwice inend_data_capture_thread()while the encoders' callbacks can still write it. So the single-field tests stay C in their order, and each atomic is loaded where it always was.obs_output_force_stop(),obs_output_actual_stop()andobs_output_signal_stop()'s stop branch decide only on single atomics, so they are unchanged.What stays C, at its point and under its condition:
obs_output_valid(); thecontext.data,raw_audio2,signalandforcetests; every atomic load and store (active,data_active,reconnecting,starting,delay_active,delay_capturing,delay_restart_refs, the end-capture thread's flags) and the stopping event; the unpause, the event resets and signals, the reconnect thread's join;info.stop,obs_output_end_data_capture(),obs_output_delay_stop(),obs_encoder_stop(),obs_encoder_shutdown_unstarted(),stop_raw_video(),audio_output_disconnect(),obs_service_deactivate(),obs_output_cleanup_delay(),log_frame_info(); the caption frees under their mutex and the keyframe tracking clear; the joins,pthread_create()and the stop parameters copied before a thread starts (#2086, #2098); the reconnect policy; every signal and every log.Nothing divides and no pointer crosses. The header copies the four flags, and
obs-output.c.hchecks them with_Static_assert. The restart count crosses aslong(32 bits on Windows) and is widened toi64. No read changes.Six commits:
libobs/obs-output-stop.c.h, declared in the newobs-output-stop.hwithoutEXPORT, so they are hidden. A scratch harness (not committed) compiled origin/master's stop and end-capture functions verbatim next to this branch's, with every read ofinfo.flags,active_delay_ns,mixer_mask,context.data,raw_audio2andreconnect_thread_activeand everystop_codewrite rewritten the same way into a logged access, over a stand-in output that logs every atomic, event, join, thread creation, encoder stop, disconnect, signal and log in order, while another thread flips the atomics, the stopping event, the delay or the restart refs, or runs a created thread, between events. 2,900,000 runs (GCC and Clang-O2, GCC-O0, ASan with UBSan under GCC-O0and Clang-O2) give the same 204,669,941 events and end states; gcov takes every branch of origin/master's functions both ways (130 of 130); 20 of 21 planted broken moves fail it, and the one that passes swaps two reads ofinfo.flags, which is never written after the output is created.test_output_stop_steps, 19 cases: six on the rules, thirteen copying the nine callers onto a recording stand-in output, end to end (each route over the atomics and the stopping event, the forced stop of a delayed output that is and is not capturing, a reconnecting output with and without data, the end with and without its signal, restart refs 0, 1 and -1, the thread creation failing, each callback, the raw mixes, and sequences).todo!(): the 19 C cases 1:1, plus edge tests against the origin/master expressions inline and proptests over values and over call sequences with another thread flipping state.libobs.ported-output-stopgroup whose PCH is only the new header;source-sets.json, the unity lists, the three export lists andci/test_ported_sources.py.port_comparisonbench file. The port changes nothing a user can see, sodocs/features.mdhas no line.active_delay_nsstops at once, and its end-capture thread cleans the delay up; an encoded output with neither flag stops no encoder; a forced stop of an inactive output still callsinfo.stop.Mutation check (failing tests per tier): 13 core mutants (each rule inverted or on the wrong flag,
> 1,<= 0,< 0, always, never, the encoded constant on the service bit) all fail Tier 1 (5 to 12 tests) and Tier 3 (2 to 5); 7 shim mutants all fail Tier 3. One shim mutant that drops the high 32 bits ofactive_delay_nsfirst survived Tier 3; the delay inputs now include every power of two and multiples of 2^32, and it fails.The
port_comparisonbench (release, x86_64 Linux, median): Rust 11.97 µs, C 11.67 µs for 1024 rounds of every decision in the callers' order, about 12 ns a round.RED → GREEN
b70e99c1d:soldr cargo test -p obs-data --test obs-tests-core -- output::output_stoppasses 5 of 25 (the constants, the shared rules and the two cases whose paths ask no new rule) and fails 20 with "not yet implemented".output::output_stoppasses 33 of 33 (25 Tier 1, 8 Tier 3). Through ctest (private Xvfb and D-Bus, own HOME and runtime directory, no sound), the full suite passes against the hybrid libobs andlibobs-c-reference, 582 of 582 each, the same 3 skipped on each (a PulseAudio default sink and the v4l2 vivid module, absent here); runs were on the GREEN commit before its rebase ontoe8bdfee69, which changes only the audio monitoring code and its tests. The exported symbol sets are unchanged (1766) and identical on the hybrid and C reference libobs, with the seven functions local; the hybrid libobs has no C object for the group.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable