Skip to content

rust: Port the encoder group reconfigure rules in obs-encoder.c to obs-output #2913

Closed

Description

@vpacher

Unit

Port the encoder group reconfigure rules of libobs/obs-encoder.c.h to rust/obs-output, as a new module encoder_group_reconfig, next to encoder_lifecycle (#2512) and encoder_audio_start (#2320).

When an active encoder in a group gets new settings (dynamic bitrate), every encoder in the group must apply them on the same frame, so that their new keyframes line up. These decisions move:

  • obs_encoder_update(), the group branch. Input: the group's reconfigure_request, encoders_reconfigured, the number of encoders in the group and the encoder's last_handled_reconfigure_request. Output: start a new request, set reconfigure_again, or do nothing.
  • encoder_group_new_reconfigure_request(): the request counter steps by one and encoders_updated_next_pts, encoders_reconfigured and reconfigure_again are reset.
  • handle_encoder_group_reconfigure_request(). It runs for each video frame from receive_video() and from the GPU encode thread (obs-video-gpu-encode.c.h). Input: the group's request counters, num_encoders_started, next_pts, frame_rate_divisors_lcm, and the encoder's cur_pts, timebase_num, frame_rate_divisor, last_reconfigure_request and last_handled_reconfigure_request. Output: apply the settings on this frame or not, the new counters, and the group's next shared frame (the encoder's next pts rounded up to a multiple of timebase_num * frame_rate_divisors_lcm).
  • gcd() and lcm() in add_connection(). rust: Port the encoder connection lifecycle in obs-encoder.c to Rust #2512 kept these in C.
  • remove_connection(): the reset of the reconfigure fields when the group becomes idle.

These stay in C:

  • obs_encoder_valid(), obs_data_apply(), the context.data, info.update and active checks;
  • the group mutex, and every read and write of the encoder and the group;
  • info.update() in do_encode() and in the GPU encode thread;
  • obs_encoder_set_group(), the group create and destroy.

C behaviour to keep and record in the characterization (no fix in this port):

  • lcm() works in int, so a large product of divisors overflows.
  • next_pts % overall_timestep divides by zero when timebase_num or the LCM is 0.
  • gcd(a, 0) divides by zero. The callers never pass 0 because the divisor is at least 1.

Plan (one PR, separate commits)

  1. A behaviour-neutral move of the decisions into libobs/obs-encoder-group-reconfig.c.h, as hidden functions on plain values.
  2. Characterization in test_encoder_group_reconfig_steps. It covers:
    • the update request: the first request, a request while encoders are still applying the previous one, a second update to an encoder that already applied it (reconfigure_again), a request after all encoders are done;
    • the frame step: a new request sets the next shared frame, the encoders that reach that frame apply the settings once, the last one starts the request that reconfigure_again held back;
    • the next shared frame: divisors 1, 2, 3 and their LCM, a pts already on the boundary, a pts just past it, the largest of the encoders' frames wins;
    • gcd() and lcm(): equal values, coprime values, one divides the other, the argument order;
    • the idle reset in remove_connection();
    • a real-libobs walk in test_encoder_group_reconfig_walk: two and three video encoders from a test encoder plugin in one group, with frame rate divisors 1 and 2, encode real frames. An obs_encoder_update() in the middle must make every encoder apply the settings on the same pts, once each. A second update while the first is still pending must run after it (reconfigure_again). It needs no GPU and no streaming service.
  3. RED, then GREEN: the safe Rust core plus shims, in a libobs.ported-encoder-group-reconfig group. Exported symbols are unchanged.
  4. Tier 3 parity against the original C: exhaustive over small counters and divisors, plus proptests over update and frame sequences for groups of 1 to 4 encoders. Also a deliberate-break check and port_comparison numbers (it runs once per video frame for each grouped encoder).

These real-libobs tests must stay green on every lane:

  • test_encoder_lifecycle_steps, test_encoder_group_null, test_multitrack_ladder
  • test_encoder_gpu_gates_steps, test_encoder_packet_ts_steps

Production check: none on the obs-rust production box. Only the multitrack video output (frontend/utility/MultitrackVideoOutput.cpp.hpp) creates encoder groups, and production does not use it. The real-libobs walk test test_encoder_group_reconfig_walk runs grouped encoders through updates on real frames instead.

Refs #2512 #2320

Activity

  1. added
    enhancement
    on Oct 29, 2026
  2. vpacher commented on Oct 29, 2026

    @vpacher
    MemberAuthor

    Claiming: #2913

    Plan as in the issue: one PR with the behaviour-neutral move, the characterization (test_encoder_group_reconfig_steps), RED/GREEN (obs-output::encoder_group_reconfig, group libobs.ported-encoder-group-reconfig) and Tier 3 parity. Before pushing: memory and time of the new tests, Windows on a local VM, and a local-gate stamp so PR CI can skip the Linux jobs. I expect a draft PR within 48 hours.

  3. added
    port
    on Oct 29, 2026
  4. added
    ready
    on Oct 29, 2026
  5. vpacher commented on Oct 29, 2026

    @vpacher
    MemberAuthor

    Starting: behaviour-neutral move, then the characterization (test_encoder_group_reconfig_steps, test_encoder_group_reconfig_walk).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions