Skip to content

win-dshow: Undo the device's roll when Autorotation is turned off - #2140

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/dshow-autorotation-off
Oct 24, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/dshow-autorotation-off

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2137

What and why

On Windows, turning off Autorotation on a Video Capture Device source left the camera turned by the last roll the device reported, until OBS restarted or the source was recreated.

  • DShowInput::OnVideoData() passes the device's roll to obs_source_set_async_rotation() only while autorotation is on and the roll changed. Nothing set the rotation back to 0 when the setting was turned off, and lastRotation kept the old roll, so turning Autorotation on again did not re-apply the same roll either.
  • DShowInput::UpdateVideoConfig(), where autorotation is read, now sets the async rotation back to 0 when Autorotation is off and a roll was applied (lastRotation != 0), and resets lastRotation to 0. The next frame with Autorotation on applies the device's roll again.
  • Threading: a settings change reaches UpdateVideoConfig() only through QueueActivate() → the source's DShow thread (DShowLoop(), Action::Activate) → Activate(), which first calls device.ResetGraph() (stops and destroys the old graph) and starts the new graph only after UpdateVideoConfig() returns. OnVideoData() runs on the DirectShow streaming thread of a running graph, so the two never touch lastRotation at the same time. That is the same window in which Activate() already rewrites autorotation, flip, videoConfig and frame, which OnVideoData() also reads; this adds no new sharing and no lock.
  • Every path with Autorotation on is unchanged: OnVideoData() makes the same decision as before, now through dshow_rotation_on_frame(), and with Autorotation on a settings update keeps lastRotation.
  • The decision is in plugins/win-dshow/dshow-rotation.h: plain C, no Windows headers, included through win-dshow.pch.hpp (BUILD.md rule 2). That lets test_dshow_rotation run it on every host; win-dshow had no test before.
  • The rotation value itself is normalized in libobs by libobs: Keep an async rotation in 0-359 #2136 (libobs: Async rotations other than 0, ±90, 180 and 270 are drawn outside the item #2121); this PR does not touch libobs.

RED → GREEN

  • RED commit: 748ed39 test: Fail the dshow rotation reset when Autorotation is turned off. Adds dshow-rotation.h with dshow_rotation_on_frame() (today's OnVideoData() check) and dshow_rotation_on_settings() as a stub that never resets, like today's settings path, plus test_dshow_rotation (5 cases, in test-graph.json, cmocka only, no libobs). Built and run on Linux with libobs C and with hybrid libobs: 2 of 5 fail in both, test_off_resets_applied_rotation and test_on_again_reapplies_same_roll (dshow_rotation_on_settings(false, &last) is not true); the 3 controls pass.
  • GREEN: 2ac970c (rebased onto master after libobs: Keep an async rotation in 0-359 #2136 merged; only the docs/features.md line moved, and the runs below were on the same code as bd25635). test_dshow_rotation 5/5 with libobs C and with hybrid libobs. The test does not link libobs, so libobs-c-reference does not apply. Windows: the cmake/cross check (-DOBS_CROSS_TARGET=win-x64, soldr clang, Windows SDK, the pinned Windows deps) compiles win-dshow-cross through the real win-dshow.windows+ group and its precompiled header with no warning in the changed files (the one warning is the existing -Wswitch in ffmpeg-decode.c.h). Local gate on 2ac970c: --lane lint, --test-diff origin/master (obs-build, obs-studio-rust, obs-sys: 66/66) and --lane cross pass. --lane cross only checks the Rust workspace for Windows and macOS; it does not compile win-dshow.
  • Real app: not run. This was not run on Windows or with a camera that reports its roll; the fix is verified by the test above, the Windows cross-compile and reading the code.

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 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): none. This changes a precompiled header (plugins/win-dshow/build/win-dshow.pch.hpp), so BUILD.md asks for a full Windows and macOS build (gh workflow run ci.yml --ref <branch>) before merge
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 11:54
A Video Capture Device source with Autorotation on passes the device's
roll to obs_source_set_async_rotation() from OnVideoData(), and nothing
sets it back when Autorotation is turned off (obs-rust#2137). Adds
plugins/win-dshow/dshow-rotation.h: dshow_rotation_on_frame() is
today's OnVideoData() check, dshow_rotation_on_settings() a stub that,
like today's settings path, never resets. test_dshow_rotation is plain
C with no Windows headers, so it runs on every host.
test_off_resets_applied_rotation and test_on_again_reapplies_same_roll
fail.

Refs obs-rust#2137
With Autorotation on, OnVideoData() passes the device's roll to
obs_source_set_async_rotation() whenever it changes. Turning
Autorotation off stopped that, but left the last roll applied, so the
camera stayed turned until OBS restarted or the source was recreated.

UpdateVideoConfig(), which reads Autorotation, now sets the rotation
back to 0 when Autorotation is off and a roll was applied, and resets
lastRotation to 0, so turning Autorotation on again re-applies the
device's roll even when it has not changed. It runs on the DShow thread
after ResetGraph() and before the new graph starts, so OnVideoData() is
not running then. Every path with Autorotation on is unchanged.

The decision is in dshow-rotation.h (in the win-dshow precompiled
header), which test_dshow_rotation drives on every host.

Fixes obs-rust#2137
@rdoupe
rdoupe force-pushed the fix/dshow-autorotation-off branch from bd25635 to 2ac970c Compare October 24, 2026 12:24
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit af31b65 Oct 24, 2026
35 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.

win-dshow: Turning off Autorotation leaves the camera rotated

2 participants