Repository navigation
libobs: Port the WASAPI monitor delay decisions - #3107
Merged
Merged
Conversation
rdoupe
force-pushed
the
fix/rust-port-wasapi-monitor-delay-s-311
branch
from
October 31, 2026 01:26
2fc1e46 to
6421450
Compare
Behaviour-neutral extraction before the Rust port. The decisions of process_audio_delay() in audio-monitoring/win32/wasapi-output.c.h move to the new audio-monitoring/monitor-delay.c.h, as hidden functions on plain integers declared without EXPORT in monitor-delay.h: - audio_monitor_delay_stale(): the stale cut. More than 1 s since the last packet arrived means the delay buffer is stale; the receive time is stored either way; - the front packet's verdict, in the steps process_audio_delay() takes: audio_monitor_delay_diff() (the timestamp less the device padding, written back, and its difference from the source's last video timestamp), the "bad diff" gate in two parts, audio_monitor_delay_unsynced() (no video timestamp yet, or more than 5 s apart) and audio_monitor_delay_stalled() (the video stalled past AUDIO_MONITOR_VIDEO_STALL_NS), then audio_monitor_delay_judge_diff() (hold more than 75 ms ahead, drag more than 75 ms behind, else play). The timestamp less the padding and the difference stay in C for the two DEBUG_AUDIO logs. The gate is two functions, not one, because the C reads the stall count last and only when the first two tests leave the gate open: wasapi-output.c keeps the || between them, so monitor->time_since_prev is still read only then, after the padding's util_mul_div64(). The thresholds are named (AUDIO_MONITOR_DELAY_STALE_NS, _MAX_DIFF_NS and _SYNC_NS) with the literals they had, so every comparison keeps its types: the uint64_t subtraction of the stale cut, the cast to int64_t of the difference and llabs() of it. wasapi-output.c keeps the delay buffer (deque_free(), every push, peek and pop), da_resize(), os_gettime_ns(), the reads of last_frame_ts, sync_offset, the sample rate and the stall count where they were, both util_mul_div64() calls, the "more are queued" test after the pops (a drag verdict drops the packet only then), the two DEBUG_AUDIO logs, the loop and its returns. The stall tracking, audio_monitor_track_video_ts(), stays a static inline in monitor-video-sync.h: test_monitor_video_sync and test_media_cover_art_monitor include the header and call it. Checked in a scratch harness (not committed). It builds origin/master's struct audio_monitor and process_audio_delay() verbatim, and this branch's with the moved file, each over the real deque, darray, util_uint64.h and monitor-video-sync.h, with os_gettime_ns(), util_mul_div64(), blog() and every read of monitor->time_since_prev logging each call or read and its value. Each run is 1 to 40 packets on one monitor: 1 or 2 channels, rates of 1, 7, 8000, 44100, 48000, 48001, 96000 and 192000, 0 to 4096 frames, paddings of 0, 1, 480, 4800, 48000, 96000, UINT32_MAX and random, clocks that step by 0, 1, 1 s - 1, 1 s, 1 s + 1 and random, video timestamps that are 0, stand still, advance and jump, sync offsets of 0, +-75 ms (+-1), +-5 s (+-1), +-10 s and random, and packet timestamps placed at those differences from the video, the padding included, or random. The log holds every call, each result, the data returned (which buffer, and a hash of its samples), the queue size and the three state fields. 10,000 runs over 5 seeds in 16 builds (GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery, with and without DEBUG_AUDIO): the logs are identical in every build, 917,046 lines each side (937,529 with DEBUG_AUDIO); seed 1 reads the stall count 16,994 times in its 41,000-odd front judgements. Every branch of origin/master's process_audio_delay() is taken both ways (gcov) except the loop's exit, which cannot be reached: a packet is pushed before the loop, and a drag needs more queued after the pops. 17 deliberately broken moves were planted, and the harness fails all 17: the stale cut at >=, at 1 s + 1 and without storing the time, the no-video test dropped, the 5 s, stall, rush and drag tests at >= and <=, the padding added, the drag without the gate, hold and drag swapped, and in the caller the drag without the queue test, the padding's duration from the frame count, the stall count read from the wrong field, the stale cut moved after the push, the stall part asked first and the gate joined with | (both read the stall count unconditionally). A single judge() taking the stall count as an argument fails it too. The new file has its own group, libobs.monitor-delay, in the Windows sources, with a precompiled header of monitor-delay.h, monitor-video-sync.h (the stall threshold) and <stdlib.h>, so a C test can compile it on any OS; libobs-windows.pch.h includes the header for wasapi-output.c. clang-cl /W4 /WX against the Windows SDK accepts the new group, and libobs.windows+ with and without DEBUG_AUDIO, with no new warning. The exported symbol sets are unchanged: Linux and macOS build neither file, and on Windows the functions are not exported. git blame on the moved lines shows upstream commits by Lain (the delay and its sync offset) and the fork's own stall rule (e8bdfee). Refs #3105. Co-authored-by: Lain <[email protected]>
test_audio_monitor_delay_steps compiles libobs/audio-monitoring/monitor-delay.c.h (ASan and UBSan) and calls only its five hidden functions through monitor-delay.h, so it needs no Windows header and runs on every platform (11 cases). A judge() helper asks the front packet's steps in process_audio_delay()'s order, the stall count only when the gate's first part leaves it open, and counts the asks: - the thresholds (1 s, 5 s, 75 ms and the 100 ms video stall) and the verdict values; - the stale cut: at exactly 1 s and at 1 s + 1, from a receive time of 0, at the far ends of the clock, and the receive time stored every time; - each step on its own: the difference (wrapping, also below 0), the gate's two parts at their edges (no video, +-5 s, +-(5 s + 1), the ends of int64_t; 100 ms and 100 ms + 1) and the verdict with the gate open and shut, at +-75 ms, +-(75 ms + 1) and the ends of int64_t; - the stall count asked for only with a video timestamp and within 5 s; - the verdict at differences of 0, +-1, +-75 ms, +-(75 ms +- 1), +-1 s, +-5 s, +-(5 s +- 1) and beyond, with what it writes back; - no video timestamp yet: play, whatever the difference; - the video stall: up to 100 ms the audio still holds and drags, past it it plays; - the padding taken off the packet's timestamp; - timestamps past INT64_MAX, negative once cast; - a stand-in of process_audio_delay()'s loop over a queue of 20 ms packets, asking in its order: the late packets dropped up to the first within 75 ms, each in turn, the hold with the queue kept, the last packet played even when it drags, the padding, and a stalled or missing video. Characterized, not endorsed: - a clock that steps back wraps the uint64_t difference, so the queue is stale and is cut; - a padding longer than the packet's timestamp wraps the uint64_t subtraction: the front timestamp is negative once cast, so the packet drags when the video is near and plays when it is far. Not characterized: a difference of INT64_MIN (llabs() of it is undefined) and timestamps whose int64_t difference overflows. It is in the native test graph, in name order, on every platform, with monitor-delay.h and monitor-video-sync.h as watch inputs. No assert_in_range or fail_msg, so it builds with cmocka 1.x and 2.x and links on Windows. Passes on the C libobs build (11/11). No real-libobs test reaches process_audio_delay(): the WASAPI monitor runs only on Windows. Refs #3105.
RED for the port of libobs/audio-monitoring/monitor-delay.c.h to a new monitor_delay module of rust/obs-audio-monitoring, next to pulse_monitor. The safe core is a stub (todo!()): stale(), the stale cut, and the front packet's steps as the C has them: diff() (Front: the timestamp less the padding and the difference), unsynced() and stalled(), the gate's two parts, and judge(), the Verdict (Play, Hold or Drag) from the gate and the difference. The thresholds are constants: STALE_NS, MAX_DIFF_NS, SYNC_NS and VIDEO_STALL_NS. tests/audio_monitoring/monitor_delay.rs ports test_audio_monitor_delay_steps 1:1: its 11 cases under the same names (steps_*), in the same order, with the same values and expectations, the characterized-not-endorsed cases included, the C test's judge() helper as judge4() (the stall count asked only when unsynced() is false, and the asks counted), and its stand-in of process_audio_delay()'s loop written in Rust over the core. Edge cases (edge_*) check the core against a model of the origin/master C, its expressions inline: the stale cut over every pair of 50 edge values (around 0, each threshold, 10 s, INT64_MAX and UINT64_MAX), each step over those values, the whole judgement over those video timestamps with 56 differences around 0, 75 ms, 1 s and 5 s, five paddings and four stall counts, and the difference of INT64_MIN, which the C leaves undefined (llabs()) and the core plays. Three proptests: the stale cut and the judgement over full-range values, and the judgement near the thresholds. The tests are a module of the existing core category binary, obs-tests-core; no new test binary. soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring::monitor_delay:: passes 1 of 18 (the constants) and fails 17 with "not yet implemented". Refs #3105.
GREEN for #3105. Ports libobs/audio-monitoring/monitor-delay.c.h, the delay decisions of the WASAPI monitor's process_audio_delay(), to the monitor_delay module of rust/obs-audio-monitoring. wasapi-output.c stays C around it: the delay queue, the clock, every read of the source and the monitor, both util_mul_div64() calls, the "more are queued" test, the logs and the loop. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/monitor_delay.rs): - stale(): the clock less the receive time, wrapping, more than STALE_NS (1 s); the receive time is stored either way; - diff(): the timestamp less the padding, wrapping, and the difference of the two as i64, wrapping, as the C's casts and subtraction; - unsynced(): no video timestamp, or a magnitude past MAX_DIFF_NS; - stalled(): the stall count past VIDEO_STALL_NS; - judge(): Hold past SYNC_NS ahead and Drag past it behind when the gate is open, else Play. wasapi-output.c keeps the || between unsynced() and stalled(), so the stall count is still read only when the first is false. 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. No intentional difference. The one input the C leaves undefined, a difference of INT64_MIN (llabs()), has a magnitude of 2^63 here, past 5 s, so the audio plays. Shims (src/ffi/monitor_delay.rs): the five functions keep the C signatures; the verdict (0 to 2) crosses as unsigned int. A null pointer, which the C dereferences, reads as 0 and is not written; wasapi-output.c always passes its fields and locals. C side: the file leaves libobs.monitor-delay for its own ported group, libobs.ported-monitor-delay, registered in libobs/build/ported-source-sets/monitor-delay.json for Windows, with the same precompiled header contents. 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 (MSVC exports only what rust-exports.d lists, so no fragment). libobs-rust already links the crate's ffi. ci/test_ported_sources.py checks the group is ported on Windows only. test_audio_monitor_delay_steps still compiles the C file into itself, unchanged. test_audio_monitor_delay_steps_rust builds the same source without the C file and links libobs_rust-static alone (the obs-audio-monitoring member needs nothing from libobs), hybrid backend, Linux: 11 of 11. soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring::monitor_delay:: passes 18 of 18, and test_audio_monitor_delay_steps 11 of 11 on the C and hybrid builds. The exported symbols are identical on the Linux C, hybrid and C reference builds (1767 each), the five shims local (t). Refs #3105. Co-authored-by: Lain <[email protected]>
Tier 3 for the monitor_delay port. The oracle (rust/obs-c-oracle/oracle/monitor_delay.c) compiles the unchanged libobs/audio-monitoring/monitor-delay.c.h with its five functions renamed to oracle_*, and gives its constants (the three thresholds, the video stall, the verdict values and the enum's size); bound in src/monitor_delay.rs. It calls nothing but llabs() and does not divide. tests/audio_monitoring/monitor_delay_parity.rs compares the oracle, the shims and the core exactly, all three sides: - the eight constants; - the stale cut over +-3 around receive times of 0, 1, 1 s, 10 s, 2^62, INT64_MAX and UINT64_MAX with clock steps +-3 around 0, 1 s, 2 s, 2^63 and UINT64_MAX (so backwards too): 1,715 pairs; - each step alone (the gate's two parts and the verdict) over +-3 around every threshold, those video timestamps and every difference near 0, +-75 ms, +-5 s and the ends of int64_t; - the judgement, the steps put together as process_audio_delay() asks them (whether the stall count was asked for compared too), over +-3 around video timestamps of 0, 1, 10 s, 2^62, INT64_MAX and UINT64_MAX, differences of 0, +-75 ms, +-1 s, +-5 s and +-10 s, paddings of 0, 100 ms and the whole front timestamp (so it wraps), and stall counts around 100 ms, with 0 and UINT64_MAX, with what it writes back; - process_audio_delay()'s loop on the oracle, the shims and the core: runs of up to 512 packets at rates of 8,000 to 192,000 (with util_mul_div64() and the unported stall tracking as the C caller has them), sync offsets of 0 or +-10 s, clocks that step by about a packet, past 1 s and back, video timestamps that advance, stand still, jump and are 0, packet timestamps near +-75 ms and +-5 s with jitter, and paddings of 0 to 48,000 frames; every stale cut, every judgement, what plays, the queue and the receive time; - proptests (20,000 cases each, 200 runs for the loop) of the stale cut and the judgement over full-range values and near the thresholds. No intentional difference. Excluded, as the C leaves them undefined: a judgement whose int64_t difference overflows or is INT64_MIN (llabs()); timestamps of the monotonic clock never come near either. The Tier 1 tests pin what the core does with INT64_MIN. Null pointers, which the C dereferences, are checked on the Rust side only. port_comparison gets benches/port_comparison/monitor_delay.rs: 64 packets' stale cut and front judgement steps in the C's order, folded into a checksum both sides must match. Linux x86_64: Rust 534 ns, C 537 ns. It allocates nothing with bmalloc. Mutation check (done once, not committed); failing tests per mutant: | Mutant | Tier 1 | Tier 3 | |---|---|---| | stale: >= | 2 | 3 | | stale: time not stored | 3 | 3 | | stale: saturating | 3 | 3 | | diff: padding saturating | 4 | 3 | | diff: padding added | 7 | 4 | | diff: negated | 11 | 5 | | unsynced: no-video test dropped | 4 | 3 | | unsynced: 5 s at >= | 5 | 2 | | stalled: >= | 4 | 2 | | judge: rush at >= | 5 | 3 | | judge: drag at <= | 4 | 2 | | judge: drag without the gate | 10 | 5 | | judge: hold without the gate | 9 | 5 | | SYNC_NS at 74 ms | 6 | 4 | | VIDEO_STALL_NS + 1 | 6 | 3 | | Hold and Drag values swapped | 1 | 5 | | shim: receive time not written | 0 | 3 | | shim diff: front_ts not written | 0 | 4 | | shim diff: returns front_ts | 0 | 5 | | shim diff: arguments swapped | 0 | 5 | | shim diff: padding dropped | 0 | 4 | | shim unsynced: video dropped | 0 | 3 | | shim stalled: negated | 0 | 4 | | shim judge_diff: gate ignored | 0 | 5 | All 24 are killed; the shim mutants by Tier 3, the tier that reaches the shims. The proptest regression files keep seeds the mutants failed on. With SYNC_NS planted at 74 ms, test_audio_monitor_delay_steps_rust fails 3 of 11 while test_audio_monitor_delay_steps passes. Tier 1 and Tier 3 pass (18/18 and 9/9). At the reduced parity level the longest new test takes 0.81 s (the loop); peak RSS 34 MB over 25 runs; no threads of their own. Refs #3105.
rust/README.md's crate table now lists libobs/audio-monitoring/monitor-delay.c.h among the rust/obs-audio-monitoring units, and its port table has a row for it, after the PulseAudio monitor steps: the five functions (the stale cut and the front judgement's steps), what stays C in wasapi-output.c (the delay queue, the clock, every read, both util_mul_div64() calls, the "more are queued" test, the logs and the loop), the stall tracking left in monitor-video-sync.h, the wrapping arithmetic, what is characterized, the inputs the C leaves undefined, the null pointers, and the tests that cover it. The crate's description and its lib.rs module docs add the file and the module. naming.md's libobs/audio-monitoring/ row already maps the directory to the crate. No docs/features.md line: a port with no change in behaviour. Fixes #3105.
rdoupe
force-pushed
the
fix/rust-port-wasapi-monitor-delay-s-311
branch
from
October 31, 2026 01:52
6421450 to
eaf7830
Compare
rdoupe
marked this pull request as ready for review
October 31, 2026 02:49
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 #3105
What and why
Port of the delay decisions of the WASAPI monitor's
process_audio_delay()(libobs/audio-monitoring/win32/wasapi-output.c.h) torust/obs-audio-monitoring, as a new modulemonitor_delay, next topulse_monitor. On Windows they decide, for every packet of a monitored source that has video, whether its audio is held back, cut or played to stay in step with the source's video: the stale cut (more than 1 s since the last packet empties the delay queue) and the front packet's verdict (hold when more than 75 ms ahead, drop when more than 75 ms behind and more are queued, play otherwise; play too when there is no video timestamp yet, when audio and video are more than 5 s apart, or when the video has stood still for more than 100 ms).Commits:
libobs: Move the WASAPI monitor delay decisions(behaviour-neutral): five hidden functions on plain integers inlibobs/audio-monitoring/monitor-delay.c.h, declared without EXPORT inmonitor-delay.hwith the 1 s, 5 s and 75 ms thresholds named, in their own unity group,libobs.monitor-delay, with no Windows header:audio_monitor_delay_stale(), and the front judgement in the steps master takes,_diff(), the "bad diff" gate's two parts_unsynced()(no video timestamp, or more than 5 s apart) and_stalled()(video stood still), then_judge_diff(). The gate is two functions because master reads the stall count last and only when the first two tests leave the gate open:wasapi-output.ckeeps the||between them, somonitor->time_since_previs still read only then.wasapi-output.calso keeps the delay queue (every deque call),da_resize(),os_gettime_ns(), the other reads of the source and the monitor where they were, bothutil_mul_div64()calls, the "more are queued" test after the pops, the twoDEBUG_AUDIOlogs and the loop.test: Characterize the WASAPI monitor delay(test_audio_monitor_delay_steps, 11 cases, every platform; itsjudge()helper asks the steps in master's order and counts the stall asks).obs-audio-monitoring: Test the monitor delay port(RED).obs-audio-monitoring: Port the monitor delay(GREEN: core, shims, grouplibobs.ported-monitor-delayregistered inlibobs/build/ported-source-sets/monitor-delay.json, the three hidden-symbol lists,ci/test_ported_sources.py, andtest_audio_monitor_delay_steps_rust).obs-audio-monitoring: Compare monitor delay to C(oracle, Tier 3,port_comparison, mutation check).docs: Record the WASAPI monitor delay port.The video stall tracking (
audio_monitor_track_video_ts()) stays astatic inlineinmonitor-video-sync.h, unported: the existing teststest_monitor_video_syncandtest_media_cover_art_monitorinclude the header and call it, and they stay unchanged.Kept and characterized, not endorsed: a clock that steps back makes the queue stale (the
uint64_tdifference wraps); a padding longer than the packet's timestamp wraps to a front timestamp before 0, so the packet drags when the video is near and plays when it is far.No intentional difference. The inputs the C leaves undefined (an
int64_tdifference that overflows, orINT64_MINgiven tollabs()) are left out of Tier 3 and listed in the parity test header; monotonic-clock timestamps never come near them, and the core plays onINT64_MIN. Null pointers, which the C dereferences, read as 0 and are not written (wasapi-output.calways passes its fields and locals).The moved code is upstream's (Lain) and the fork's own video-stall rule; Lain is credited in the move and port commits. No upstream issue.
RED → GREEN
soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring::monitor_delay::passes 1 of 18 (the constants) and fails 17 with "not yet implemented". On the RED commit,local_gate.py --lane lintpassed and--test-diff origin/masterfailed only those 17 (5474 of 5491 passed, 6 skipped).audio_monitoring::monitor_delay18/18; Tier 3audio_monitoring::monitor_delay_parity9/9. Linux x86_64 (GCC):test_audio_monitor_delay_stepspasses 11/11 on the C build and on the hybrid tree, andtest_audio_monitor_delay_steps_rustpasses 11/11 on the hybrid tree (withSYNC_NSplanted at 74 ms in the Rust core it fails 3 of 11 while the C one passes). The monitor tests (test_audio_monitor_delay_steps, its_rustvariant,test_monitor_speaker_layout,test_monitor_video_sync,test_media_cover_art_monitor,test_source_monitoring_steps, its_rustvariant andtest_source_monitoring_type) pass 8/8 against the hybrid libobs and 8/8 againstlibobs-c-reference, none skipped, under a private Xvfb. Exported symbols identical on the C, hybrid and C reference builds (1767 each), the five shims local (t). clang-cl/W4 /WXwith the Windows SDK accepts the ported group andlibobs.windows+, with and withoutDEBUG_AUDIO. Runs were on 6421450; after the rebase onto the X11 key names port (obs-hotkey: Port the X11 key names and raw buttons #3101), again on eaf7830: the quick CI guard tests,./lint, Tier 1 and Tier 3 (27/27), the bench test, the three C test builds (11/11 each) and the export comparison (1767 each, the five shims local).Local gates (runs were on 6421450): the quick CI guard tests (build groups, ported sources, oracle stand-ins and MSVC, sorted shared lists, test graph sorted, cmocka Rust-static guard, Windows diagnostics and includes, naming) pass;
./lint,local_gate.py --lane lintand--lane crossok;./unittestRust tiers 5500/5500 passed, 6 skipped;soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsclean;soldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses. Not run locally: Tier 2 in Docker (./unittest's tier2-linux lane), and so the local-gate stamp: this host's build account can't reach the Docker socket, andci-lint local-gate runpasses lint, rust-test and cross and stops at tier2-linux. The Tier 2 tests above ran natively instead; the head is unstamped, so PR CI runs the full suite. Nothing here has run on a Windows machine: the Windows Rust tests and Tier 2 in PR CI are the first.Test cost: new tests (27): longest 0.81 s at the reduced parity level (the loop proptest), peak RSS 34 MB over 25 runs, no threads of their own.
Move check (runs were on the move commit's tree): master's
struct audio_monitorandprocess_audio_delay()and the moved one, extracted over the real deque, darray,util_uint64.handmonitor-video-sync.hwith logging stand-ins foros_gettime_ns(),util_mul_div64(),blog()and every read ofmonitor->time_since_prev, built with gcc and clang at -O0 and -O2, with and without ASan and UBSan, with and withoutDEBUG_AUDIO: 10,000 packet runs over 5 seeds give identical logs in all 16 builds (917,046 lines each side; the stall count read about 17,000 times in seed 1's 41,000-odd front judgements). Every branch of master's function is taken both ways except the loop's unreachable exit. 17 of 17 planted mutants change the log, two of them the stall read's place; a single judge taking the stall count as an argument fails it too.Mutation check of the port: 24 mutants (16 in the core, 8 in the shims), all killed; table in commit 5 (8b562ba). The shim mutants are killed by Tier 3, the tier that reaches the shims.
port_comparison(monitor_delay/packets/64, Linux x86_64): Rust 534 ns, C 537 ns for 64 packets' stale cut and front judgement steps.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-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 change)