Skip to content

rust: Port encoder pause and unpause checks #3033

Closed

Description

@rdoupe

Unit

libobs/obs-encoder.c.h: the encoder pause and unpause checks of video_pause_check() and audio_pause_check() (whether a paused encoder drops a video frame or ends its pause on it; where an audio buffer is cut at the pause start, cut at the pause end, dropped or passed), moved to libobs/obs-encoder-pause.c.h and ported to rust/obs-output (module encoder_pause, next to encoder_audio_start and encoder_packet_ts).

Phase and position

Phase 2 libobs core, outputs (core-output group), beside the output pause plan port (#3020, which writes the pause records these checks read). Tracking: #4.

Dependencies and existing tests

  • Shares the core-output unity group file and the sorted lists with the open output pause plan PR (obs-output: Port the output pause plan #3024); whichever lands second rebases. No other open PR touches obs-encoder.c.h or the group.
  • No characterization yet: test_encoder_pause_steps (cmocka, the moved file on its own) lands first, pinning video frames before, at the start of, inside and at the end of a pause; an audio buffer before the pause (passed), holding the start (cut), wholly inside (dropped) and holding the end (cut, and stamped with the pause start: characterized, not endorsed); a start exactly at a buffer's start (empty, dropped) and at its end.

Notes

  • What moves are the decisions on plain values: whether a pause is on (ts_start), the video frame's step (pass, drop, or end the pause), where a pause start falls against an audio buffer, and, while paused, whether the buffer holds the end. obs-encoder.c keeps every pause.mutex lock and unlock, the last_video_ts store (before the check, as today), both util_mul_div64() conversions (audio_frames_to_ns() for the buffer's end, ns_to_audio_frames() for each cut) with their subtractions, every write to ts_start, ts_end, the buffer's frames and timestamp, the data pointer advance, the ts_offset subtraction, pause_reset() and every caller. Each read stays where it is.
  • Intentional differences, fixed in the port and listed in its parity test:
    1. The video check ends a pause only on a frame stamped exactly ts_end. The unpause time is snapped to the frame grid of the output's first video encoder, so an encoder with a frame rate divisor of 2 or more, fed through video-io, may never see a frame at ts_end: it then drops every later frame, and since the record never clears, the output refuses every later pause. The port ends the pause on the first frame at or after ts_end (once ts_end is set).
    2. A pause and unpause that both fall inside one audio buffer cut the buffer at the start and never look at the end; every later buffer starts after ts_end, takes the "still paused" branch and is dropped, so that encoder gets no more audio and the output refuses later pauses. The port ends the pause on a paused buffer that starts after a set ts_end: the record clears and the buffer passes with its own timestamp. The audio between ts_end and the end of the buffer that was cut (at most one buffer) is still lost.
      The first needs a plugin or script setting a divisor on an encoder of a pausable output; the second a pause and unpause in quick succession (a double press of the pause hotkey, a script or a websocket client).
  • Threads: the video thread or GPU encode thread, the audio thread and the pause caller share one record under pause.mutex; the core holds no state and is asked under the lock C already holds.

Activity

  1. added
    enhancement
    port
    on Oct 30, 2026
  2. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #3033.

    1. Move: the pause decisions of video_pause_check() and audio_pause_check() into libobs/obs-encoder-pause.c.h, behaviour-neutral, checked with a move harness (gcc and clang, -O0/-O2, ASan/UBSan, planted mutants).
    2. Characterize: test_encoder_pause_steps against the moved C.
    3. RED: obs_output::encoder_pause Tier 1 tests on todo!() stubs.
    4. GREEN: the core and its C shims in a libobs.ported-encoder-pause group, with the two intentional differences in the issue (a video pause ends on the first frame at or after its end; a paused audio buffer after the end ends the pause).
    5. Tier 3: the original C as an oracle, exhaustive over a grid of pause times, timestamps and buffer lengths, proptests near the top of the u64 range; mutation.
    6. Docs: rust/README.md, naming.md, crate docs.

    One PR; the draft opens with the RED commit today, the rest follows on it. It shares the core-output group file with #3024, and whichever lands second rebases.

  3. added
    ready
    on Oct 30, 2026
  4. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by PR #3037 (merged as 4d2ae71): the encoder pause checks of video_pause_check() and audio_pause_check() now run in Rust (obs_output::encoder_pause), checked against the original C by the parity tests. The port also fixes the two stuck-pause cases: a pause and unpause inside one audio buffer no longer cuts that encoder's audio for the rest of the recording, and an encoder with a frame rate divisor no longer stays paused for good.

    Left: the audio between the unpause time and the end of the one buffer that was cut is still lost. The pause mutex, the two util_mul_div64() conversions, every write to the pause record and the buffer, and the callers stay in C in obs-encoder.c.

    Follow-up issue: none filed. Nothing else in this unit is open, and the tracking issue (#4) has no checkbox for it to tick.

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