Skip to content

rust: Port the video frame pacing step (video_sleep) in obs-video.c to obs-core #2738

Closed

Description

@vpacher

Unit

Port the frame pacing decisions of video_sleep() in libobs/obs-video.c.h to rust/obs-core, as a new module video_pacing, next to video_output_step (#2165) and video_copy_plan (#2118). The graphics thread calls video_sleep() once per frame (obs_graphics_thread_loop). These decisions move:

  • The frame time step. Input: the current frame time, the interval, whether os_sleepto_ns() reached the next frame time, and the current time. Output:
    • the new frame time (the next frame time, or the frame time on the interval grid after a late wake-up);
    • the frame count (1, or the number of whole intervals since the current frame time, at least 1);
    • the lagged frames for obs_video_stats_add_frames() (count − 1).
  • The encoder-group start: whether a ready encoder's group gets its start_timestamp (all encoders of the group started, and no start timestamp yet), and which time it gets. Note for the characterization: C gives the group the new frame time (*p_time after the step), and the frame info gets the old one (cur_time). The characterization pins this as it is.

These stay in C:

  • os_sleepto_ns() and os_gettime_ns() (C passes their results);
  • obs_video_stats_add_frames();
  • the ready-encoder-group list, the weak-encoder references and both mutexes;
  • the vframe_info deque pushes for the raw and GPU mixes, and the mix list with its mutex.

Plan (one PR, separate commits)

  1. A behaviour-neutral move of the two decisions into libobs/obs-video-pacing.c.h, as hidden functions on plain values.
  2. Characterization in test_video_pacing_steps. It covers:
    • the sleep reached the next frame time (count 1, no lag);
    • a late wake-up by less than one interval, by exactly one, and by several intervals (count, lag and the new frame time on the grid);
    • a current time earlier than the frame time (the clamp to one interval);
    • large time jumps (after suspend/resume) near the limits of the int count and of the uint32_t stats arguments;
    • the encoder-group start for each combination of "all started" and "start timestamp already set", and the old-vs-new time detail above.
  3. RED, then GREEN: the safe Rust core plus shims, in a libobs.ported-video-pacing group. Exported symbols are unchanged.
  4. Tier 3 parity against the original C: exhaustive over the flags and small interval multiples, plus a proptest over full-range times and intervals. Also a deliberate-break check and port_comparison numbers (this runs once per frame).

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

  • test_video_output_step_steps
  • test_video_copy_plan_steps
  • test_video_output_formats
  • test_raw_output_video_reset
  • test_encoding_lag_rescale
  • test_encoder_group_null
  • test_encoder_lifecycle_steps
  • test_encoder_audio_start_steps
  • test_media_restart_stale_frame

Production check after the merge: the obs-rust production box (Linux, NDI output, 25 fps) gets a before/after run of the render loop (lagged frames, CPU, wake-ups of the graphics thread).

Refs #2165 #2118

Activity

  1. vpacher commented on Oct 28, 2026

    @vpacher
    MemberAuthor

    Claiming: #2738

    Plan as in the issue: one PR with the behaviour-neutral move, the characterization (test_video_pacing_steps), RED/GREEN (obs-core::video_pacing, group libobs.ported-video-pacing) and Tier 3 parity. I will show a draft PR with the move and the characterization first.

  2. added
    ready
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions