Skip to content

frontend: Add Enhanced Broadcasting encoder overrides - #162

Merged
zackees merged 3 commits into
obs-rust:masterfrom
nathan-v:frontend/eb-encoder-overrides
Oct 11, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
nathan-v:frontend/eb-encoder-overrides

Conversation

@nathan-v

@nathan-v nathan-v commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #19

@AscendancyDotA this is for the Enhanced Broadcasting lag you reported in obsproject/obs-studio#13933 (Sunshine + Moonlight, NVENC, B-frames and lookahead forced by Twitch). Twitch still chooses the ladder. These controls change the encode on this machine after that config is loaded, and the service does not see them.

The read-only ladder preview is now #181. That PR is independent of this one. It does not change encoder creation.

What changed

  • Stream settings, Enhanced Broadcasting: Disable B-frames, Disable lookahead, Preset (Fastest through Slowest), and Tuning (High Quality, Ultra High Quality, Low Latency, Ultra Low Latency). Default is the service value.
  • The same choice is translated into each encoder's own setting: NVENC P1–P7 and hq/ll/ull/uhq, Quick Sync TU7–TU1 and latency, AMF speed/balanced/quality and pre-analysis, x264 ultrafast–veryslow and zerolatency. A rung whose encoder has no equivalent keeps the service value, and the log says so.
  • NVENC treats an explicit lookahead off as off, including when the preset would turn it on. lookaheadDepth and enableLookahead are stripped from Go Live opts when lookahead is disabled. Ultra High Quality still forces at least 4 B-frames, and both the frontend and obs-nvenc log that.

Testing

Windows, RTX 4090, this branch. Twitch Enhanced Broadcasting, H.264 ladder, five rungs. Each stream connected and was stopped by the user.

  • Disable B-frames and Disable lookahead, service tune hq: every rung logged b-frames: 0 and lookahead: false (0 frames). The two rungs that asked for lookaheadDepth=4 had that option removed.
  • Slowest plus Ultra High Quality, with both disable switches on: every rung logged preset: p7 and tuning: uhq, then Forcing number of b-frames to 4 for UHQ tune. Lookahead stayed off.
  • Fastest plus Ultra Low Latency, with both disable switches on: every rung logged preset: p1, tuning: ull, b-frames: 0, and lookahead: false (0 frames). No B-frame force line.

Custom RTMP, one rung, connection to localhost refused after the encoder was created:

  • obs_x264: veryfast/film/bf 3 became ultrafast, zerolatency, and bf 0. x264 logged preset: ultrafast and tune: zerolatency.
  • h264_texture_amf while OBS was rendering on the RTX 4090: preset quality became speed, bf 2 became 0, pre-analysis turned off, and the ull tune was skipped. Texture init logged Wrong adapter and the AMF fallback encoder logged preset: speed, b-frames: 0, and pre-analysis: false.

Review follow-up

The preset, tune, B-frame, and lookahead decisions are plain C, committed tests first. The RED stubs return empty: mtv_translate_encoder_override zeroes its output, mtv_filter_lookahead_opts clears the destination and returns false, and the NVENC helpers return false or 0.

  • RED b7edaf098. test_multitrack_encoder_override and test_nvenc_override link those stub C files and do not link libobs. test_nvenc_preset_and_tune_table fails because the preset key is null. test_explicit_off_beats_preset_lookahead fails because nvenc_lookahead_force_off(true, false) returns false.
  • GREEN 61eb66469. Those tests pass: seven multitrack cases and two NVENC cases. They cover the NVENC, legacy NVENC, Quick Sync, AMF, and x264 tables, a tune with no equivalent, UHQ forcing at least 4 B-frames, and stripping lookaheadDepth= / enableLookahead= only when lookahead is disabled.

mtv_translate_encoder_override chooses the setting from the encoder id. Current NVENC writes preset and keeps uhq. Legacy NVENC writes preset2 and maps uhq to hq. SVT-AV1 and AOM keep their integer presets. Any other id keeps the service value. A tune other than hq, ll, ull, or uhq is skipped. The settings page only stores those four.

The ladder-preview removal is squashed into the first commit, f15525e99, so this history does not add the preview and then delete it. #181 remains its own branch. Replaced head of this rewrite: 8b1494afc. This machine has no Docker, so the cmocka CI lane and the local-gate stamp were not run here. The two C tests were compiled and run locally with VS 2022 /W4 /WX (nine tests, exit 0).

@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Thanks, and the manual run evidence is good. Before this can merge, the project needs RED→GREEN automated tests (docs/rust-port/coordination.md section 4; same approach as #112 and #109). Most of this is pure logic that doesn't need a GPU or a live Twitch session:

  1. Override → encoder setting translation. Factor the preset/tuning/B-frame/lookahead mapping (NVENC P1–P7 and hq/ll/ull/uhq, Quick Sync TU7–TU1, AMF speed/balanced/quality, x264 ultrafast–veryslow/zerolatency, "keeps the service value when there is no equivalent") into a plain C (or Qt-free C++) function with a header. Add a cmocka test in test/cmocka/tests.d/ that builds just that file, and assert the table, including the "no equivalent" and "UHQ forces ≥4 B-frames" cases.
  2. Go Live opts filtering. Test that lookaheadDepth/enableLookahead are stripped when lookahead is disabled and kept otherwise.
  3. obs-nvenc. If the explicit-lookahead-off decision can be expressed as a small helper, test that too: preset would enable lookahead, override says off, result off.

Commit order: the tests first, failing against stubs or the current code, then the implementation. New cmocka tests go in test/cmocka/tests.d/<test>.cmake since #168; avoid fail_msg() (Windows cmocka doesn't export cm_print_error). It would also help to split the read-only ladder preview into its own PR, since it's independent of the overrides.

@nathan-v
nathan-v force-pushed the frontend/eb-encoder-overrides branch from 8f7dd9c to 4628a06 Compare October 11, 2026 01:09
@nathan-v
nathan-v requested a review from zackees as a code owner October 11, 2026 01:09
@nathan-v

Copy link
Copy Markdown
Contributor Author

The mapping is now plain C, with the tests committed first.

RED ea0cfa7d5. The cmocka binaries link frontend/utility/multitrack-encoder-override.c and plugins/obs-nvenc/nvenc-override.c with empty stubs. test_nvenc_preset_and_tune_table fails because the preset key is null. test_explicit_off_beats_preset_lookahead fails because nvenc_lookahead_force_off(true, false) returns false.

GREEN 4628a06bb. The same tests pass: seven multitrack cases and two NVENC cases. They check the NVENC P1–P7 and hq/ll/ull/uhq table (legacy NVENC writes preset2 and maps uhq to hq, and current NVENC still forces at least 4 B-frames for uhq), Quick Sync TU7–TU1, AMF speed/balanced/quality, x264 ultrafast–veryslow and zerolatency, a tune with no equivalent, and that lookaheadDepth= / enableLookahead= are removed only when lookahead is disabled. lookaheadDepthExtra stays. I compiled and ran that locally with VS 2022. RelWithDebInfo obs64.exe and obs-nvenc.dll also built. This machine has no Docker, so the cmocka CI job and the local-gate stamp were not run.

obs-nvenc calls nvenc_lookahead_enabled, nvenc_lookahead_force_off, and nvenc_bframes_for_uhq. The UHQ warning still logs only when the B-frame count changes.

Rebased onto master. The replaced head was 8f7dd9ca0.

The read-only ladder preview is still in this PR. Splitting it can be a follow-up.

@nathan-v

Copy link
Copy Markdown
Contributor Author

The read-only ladder preview is now its own pull request: #181 (frontend/eb-ladder-preview, 8c7f23de9).

#162 no longer contains that table, the preview button, or the non-interactive Go Live download. 8b1494afc is the removal. The encoder overrides and the cmocka tests are unchanged.

@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Reviewed head 8b1494a. Base is master. The helper split and the test layout are what I asked for, but there is one build break to fix first.

Must change before merge:

  1. test/cmocka/test_multitrack_encoder_override.c:40 and test/cmocka/test_nvenc_override.c:10 (and every later UNUSED_PARAMETER(state);) use a macro that neither file defines or includes. It comes from libobs/util/c99defs.h. The existing cmocka tests get it by linking OBS::libobs. These two targets (tests.d/test_multitrack_encoder_override.cmake, tests.d/test_nvenc_override.cmake) deliberately don't link it. I syntax-checked both files against a stub cmocka header, and gcc fails with implicit declaration of function 'UNUSED_PARAMETER'. The real cmocka header doesn't define it either, so the Linux Tier 2 build should fail the same way. Fix it by dropping the UNUSED_PARAMETER lines and writing (void)state;, or by defining the macro locally. Don't pull libobs into these builds, since the point is that they stay standalone.
  2. The Tier 2 cmocka run has not passed. Your last comment says it wasn't run (no Docker). Please confirm green on CI after the fix, with the Rust port OFF and ON if that matrix applies.

Non-blocking:

Optional: none.

Not ready to merge until item 1 is fixed and CI is green.

@nathan-v
nathan-v force-pushed the frontend/eb-encoder-overrides branch from 8b1494a to 61eb664 Compare October 11, 2026 01:55
@nathan-v

Copy link
Copy Markdown
Contributor Author

UNUSED_PARAMETER is gone from both standalone tests. They write (void)state, the same as test_product_name.c, and they still do not link libobs. That change is in the RED commit, b7edaf098, so the RED files compile on their own. I compiled both with VS 2022 /W4 /WX and a stand-in cmocka header: 2 NVENC tests and 7 multitrack tests, both executables exited 0. That is not the Tier 2 lane. This machine has no Docker, so I have not run cmocka with the Rust port off or on.

The preview-removal commit is squashed into f15525e99. RED stubs return empty: the translate function zeroes its output, the opts filter clears the buffer and returns false, and the NVENC helpers return false or 0. GREEN is 61eb66469. #181 is independent of this PR.

Please rebase this onto master and stamp it. The replaced head is 8b1494afc.

Twitch's Go Live config sets B-frames, lookahead, preset, and tuning.
Apply local overrides after that config is loaded. An explicit NVENC
lookahead off stays off.
The preset, tune, B-frame, and lookahead table, the Go Live opts filter,
and the NVENC lookahead and UHQ decisions are cmocka tests linked to plain
C files. Those files return empty results, so
test_nvenc_preset_and_tune_table stops on a null preset key and
test_explicit_off_beats_preset_lookahead stops because
nvenc_lookahead_force_off(true, false) is false.

Refs obs-rust#19
mtv_translate_encoder_override maps one UI choice onto NVENC, legacy
NVENC, Quick Sync, AMF, x264, SVT-AV1, and AOM. Encoders outside that
table keep the service value. obs-nvenc uses nvenc_lookahead_enabled,
nvenc_lookahead_force_off, and nvenc_bframes_for_uhq when it programs
the session.

The cmocka tests added in the previous commit pass: seven multitrack
cases and two NVENC cases, including a tune with no equivalent and UHQ
forcing at least 4 B-frames.

Refs obs-rust#19

Local-Gate: v1 tree=d8043dcdfb165a854609413e95d47c1b9787925c secs=177 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791684336,"gate":"rust/all/fmt","host":"linux-x86_64","key":"72bd0d455d8c5d446e418f551d500b30782f29eb9dd6abb408583a0043fa3859","lane":"lint","parents":["25bfb8ae60ba4d12a6277ce7b4554432e82c9c48"],"secs":93,"stamp":"1e4cd47a13478d94ca8daf16c111cd83","tree":"d8043dcdfb165a854609413e95d47c1b9787925c","v":1,"via":"run"}
Ci-Attestation: {"at":1791684336,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"72bd0d455d8c5d446e418f551d500b30782f29eb9dd6abb408583a0043fa3859","lane":"lint","parents":["25bfb8ae60ba4d12a6277ce7b4554432e82c9c48"],"secs":93,"stamp":"f69ce2e3c4863fc51e9db00e36c6bf77","tree":"d8043dcdfb165a854609413e95d47c1b9787925c","v":1,"via":"run"}
Ci-Attestation: {"at":1791684336,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"33485dc3078001d9470d1d04eb699382a8abf25acf82763fdcd69a66c05f56a7","lane":"rust-test","parents":["25bfb8ae60ba4d12a6277ce7b4554432e82c9c48"],"secs":36,"stamp":"61b1343643a3bb1cc519c698c43e1cca","tree":"d8043dcdfb165a854609413e95d47c1b9787925c","v":1,"via":"run"}
Ci-Attestation: {"at":1791684336,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f392b4bde3d95281e58453f6b1a042cf05525eec56e03480a70cb24e05ed9767","lane":"tier2-linux","parents":["25bfb8ae60ba4d12a6277ce7b4554432e82c9c48"],"secs":48,"stamp":"05957d5d9606842543c4727f91a5e672","tree":"d8043dcdfb165a854609413e95d47c1b9787925c","v":1,"via":"run"}
@zackees
zackees force-pushed the frontend/eb-encoder-overrides branch from 61eb664 to e55ea8d Compare October 11, 2026 02:05
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified head 61eb66469 locally, then rebased onto master and stamped it. The new head is e55ea8d10 (RED 25bfb8ae6, GREEN e55ea8d10).

  • RED (b7edaf098): Tier 2 OFF ran 48 of 50 tests passing. test_multitrack_encoder_override failed 7 of 7 and test_nvenc_override failed as well, both against the empty stubs.
  • GREEN (61eb66469): Tier 2 passed 50 of 50 with ENABLE_RUST_LIBOBS OFF and 50 of 50 with it ON. The exported symbol set is the same OFF and ON.
  • Local gate on the rebased head: lint, rust-test and tier2-linux all passed.

Non-blocking nit: the GREEN mtv_translate_encoder_override dropped the stub's if (!out) return; guard. Every caller passes a stack struct, so it doesn't matter now. Merging once CI is green.

@zackees
zackees merged commit 246ba33 into obs-rust:master Oct 11, 2026
23 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.

Enhanced Broadcasting forces B-frames (NVENC): add a user override for low-latency/remote-desktop setups (from upstream #13933)

2 participants